Skip to content

Commit 9605a68

Browse files
HCK-14640: [FE] Add support for functional indexes (#184)
* HCK-14640: add config for index expressions * HCK-14640: handle index expressions * HCK-14640: add comments
1 parent 51e221d commit 9605a68

2 files changed

Lines changed: 196 additions & 18 deletions

File tree

forward_engineering/ddlProvider/ddlHelpers/indexHelper.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ const {
1010
const assignTemplates = require('../../utils/assignTemplates');
1111
const templates = require('../templates');
1212

13+
/**
14+
* @param {object} params
15+
* @param {Record<string, unknown>} params.index
16+
* @returns {string[]}
17+
*/
18+
const getIndexExpressions = ({ index }) => {
19+
return _.map(index.indxExpression, ({ value = '' }) => _.trim(value)).filter(Boolean);
20+
};
21+
1322
const mapIndexKey = ({ name, sortOrder, nullsOrder, collation, opclass }) => {
1423
const sortOrderStr = sortOrder ? ` ${sortOrder}` : '';
1524
const nullsOrderStr = nullsOrder ? ` ${nullsOrder}` : '';
@@ -20,8 +29,10 @@ const mapIndexKey = ({ name, sortOrder, nullsOrder, collation, opclass }) => {
2029
return `${wrapInQuotes(name)}${collationStr}${opclassStr}${sortOrderStr}${nullsOrderStr}`;
2130
};
2231

23-
const getIndexKeys = ({ columns = [], isParentActivated, isAllColumnsDeactivated }) => {
24-
return getColumnsList(columns, isAllColumnsDeactivated, isParentActivated, mapIndexKey);
32+
const getIndexKeys = ({ columns = [], indexExpressions, isParentActivated, isAllColumnsDeactivated }) => {
33+
return indexExpressions.length
34+
? ' (' + indexExpressions.join(', ') + ')'
35+
: getColumnsList(columns, isAllColumnsDeactivated, isParentActivated, mapIndexKey);
2536
};
2637

2738
const getIndexOptions = (index, isParentActivated) => {
@@ -93,8 +104,10 @@ const getValue = value => {
93104

94105
const createIndex = (tableName, index, dbData, isParentActivated = true) => {
95106
const isNameEmpty = !index.indxName && index.ifNotExist;
107+
const indexExpressions = getIndexExpressions({ index });
108+
const hasKeys = index.columns.length || indexExpressions.length;
96109

97-
if (!index.columns.length || isNameEmpty) {
110+
if (!hasKeys || isNameEmpty) {
98111
return '';
99112
}
100113

@@ -116,6 +129,7 @@ const createIndex = (tableName, index, dbData, isParentActivated = true) => {
116129

117130
const keys = getIndexKeys({
118131
columns: indexColumns,
132+
indexExpressions,
119133
isParentActivated,
120134
isAllColumnsDeactivated,
121135
});

properties_pane/entity_level/entityLevelConfig.json

Lines changed: 179 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,21 +1051,50 @@ making sure that you maintain a proper JSON format.
10511051
}
10521052
},
10531053
"dependency": {
1054-
"key": "index_method",
1055-
"value": "btree"
1054+
"type": "and",
1055+
"values": [
1056+
{
1057+
"key": "index_method",
1058+
"value": "btree"
1059+
},
1060+
{
1061+
"type": "or",
1062+
"values": [
1063+
{
1064+
"key": "indxExpression",
1065+
"isEmpty": true
1066+
},
1067+
{
1068+
"key": "indxExpression",
1069+
"exist": false
1070+
}
1071+
]
1072+
}
1073+
]
10561074
},
10571075
"validation": {
10581076
"required": true,
10591077
"minLength": 1
10601078
}
10611079
},
10621080
{
1081+
//The config has been duplicated to disable columns validation for func indexes
10631082
"propertyName": "Columns",
10641083
"propertyKeyword": "columns",
10651084
"propertyType": "fieldList",
10661085
"template": "orderedList",
10671086
"propertyTooltip": "The name of a column of the table.",
10681087
"attributeList": {
1088+
"sortOrder": {
1089+
"propertyType": "select",
1090+
"options": ["ASC", "DESC"],
1091+
"propertyTooltip": "Specifies sort order"
1092+
},
1093+
"nullsOrder": {
1094+
"propertyType": "select",
1095+
"options": ["", "NULLS FIRST", "NULLS LAST"],
1096+
"propertyTooltip": "Specifies that nulls sort order"
1097+
},
10691098
"collation": {
10701099
"propertyType": "text",
10711100
"placeholder": "Collation",
@@ -1078,27 +1107,86 @@ making sure that you maintain a proper JSON format.
10781107
}
10791108
},
10801109
"dependency": {
1081-
"type": "or",
1110+
"type": "and",
10821111
"values": [
10831112
{
10841113
"key": "index_method",
1085-
"value": "hash"
1086-
},
1087-
{
1088-
"key": "index_method",
1089-
"value": "gist"
1114+
"value": "btree"
10901115
},
10911116
{
1092-
"key": "index_method",
1093-
"value": "spgist"
1094-
},
1117+
"type": "and",
1118+
"values": [
1119+
{
1120+
"key": "indxExpression",
1121+
"isEmpty": false
1122+
},
1123+
{
1124+
"key": "indxExpression",
1125+
"exist": true
1126+
}
1127+
]
1128+
}
1129+
]
1130+
}
1131+
},
1132+
{
1133+
"propertyName": "Columns",
1134+
"propertyKeyword": "columns",
1135+
"propertyType": "fieldList",
1136+
"template": "orderedList",
1137+
"propertyTooltip": "The name of a column of the table.",
1138+
"attributeList": {
1139+
"collation": {
1140+
"propertyType": "text",
1141+
"placeholder": "Collation",
1142+
"propertyTooltip": "The name of the collation to use for the index."
1143+
},
1144+
"opclass": {
1145+
"propertyType": "text",
1146+
"placeholder": "Opclass",
1147+
"propertyTooltip": "The name of an operator class."
1148+
}
1149+
},
1150+
"dependency": {
1151+
"type": "and",
1152+
"values": [
10951153
{
1096-
"key": "index_method",
1097-
"value": "gin"
1154+
"type": "or",
1155+
"values": [
1156+
{
1157+
"key": "index_method",
1158+
"value": "hash"
1159+
},
1160+
{
1161+
"key": "index_method",
1162+
"value": "gist"
1163+
},
1164+
{
1165+
"key": "index_method",
1166+
"value": "spgist"
1167+
},
1168+
{
1169+
"key": "index_method",
1170+
"value": "gin"
1171+
},
1172+
{
1173+
"key": "index_method",
1174+
"value": "brin"
1175+
}
1176+
]
10981177
},
10991178
{
1100-
"key": "index_method",
1101-
"value": "brin"
1179+
"type": "or",
1180+
"values": [
1181+
{
1182+
"key": "indxExpression",
1183+
"isEmpty": true
1184+
},
1185+
{
1186+
"key": "indxExpression",
1187+
"exist": false
1188+
}
1189+
]
11021190
}
11031191
]
11041192
},
@@ -1107,6 +1195,69 @@ making sure that you maintain a proper JSON format.
11071195
"minLength": 1
11081196
}
11091197
},
1198+
{
1199+
//The config has been duplicated to disable columns validation for func indexes
1200+
"propertyName": "Columns",
1201+
"propertyKeyword": "columns",
1202+
"propertyType": "fieldList",
1203+
"template": "orderedList",
1204+
"propertyTooltip": "The name of a column of the table.",
1205+
"attributeList": {
1206+
"collation": {
1207+
"propertyType": "text",
1208+
"placeholder": "Collation",
1209+
"propertyTooltip": "The name of the collation to use for the index."
1210+
},
1211+
"opclass": {
1212+
"propertyType": "text",
1213+
"placeholder": "Opclass",
1214+
"propertyTooltip": "The name of an operator class."
1215+
}
1216+
},
1217+
"dependency": {
1218+
"type": "and",
1219+
"values": [
1220+
{
1221+
"type": "or",
1222+
"values": [
1223+
{
1224+
"key": "index_method",
1225+
"value": "hash"
1226+
},
1227+
{
1228+
"key": "index_method",
1229+
"value": "gist"
1230+
},
1231+
{
1232+
"key": "index_method",
1233+
"value": "spgist"
1234+
},
1235+
{
1236+
"key": "index_method",
1237+
"value": "gin"
1238+
},
1239+
{
1240+
"key": "index_method",
1241+
"value": "brin"
1242+
}
1243+
]
1244+
},
1245+
{
1246+
"type": "and",
1247+
"values": [
1248+
{
1249+
"key": "indxExpression",
1250+
"isEmpty": false
1251+
},
1252+
{
1253+
"key": "indxExpression",
1254+
"exist": true
1255+
}
1256+
]
1257+
}
1258+
]
1259+
}
1260+
},
11101261
{
11111262
"propertyName": "Columns",
11121263
"propertyKeyword": "columns",
@@ -1127,6 +1278,19 @@ making sure that you maintain a proper JSON format.
11271278
]
11281279
}
11291280
},
1281+
{
1282+
"propertyName": "Expressions",
1283+
"propertyKeyword": "indxExpression",
1284+
"propertyType": "group",
1285+
"propertyTooltip": "Specify more detailed expression for index",
1286+
"structure": [
1287+
{
1288+
"propertyName": "value",
1289+
"propertyKeyword": "value",
1290+
"propertyType": "text"
1291+
}
1292+
]
1293+
},
11301294
{
11311295
"propertyName": "Include non-key columns",
11321296
"propertyKeyword": "include",

0 commit comments

Comments
 (0)