Skip to content

Commit fe09546

Browse files
committed
Add specialized datatypes
1 parent c9b209b commit fe09546

26 files changed

+680
-38
lines changed

forward_engineering/api.js

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ module.exports = {
2828
const host = modelData.host || 'localhost';
2929
const port = modelData.port || 9200;
3030
const indexName = indexData.name || "";
31+
const majorVersion = +(modelData.dbVersion || '').split('.').shift();
32+
const includeTypeName = majorVersion >= 7 ? '&include_type_name=true' : '';
3133

32-
return `curl -XPUT '${host}:${port}/${indexName.toLowerCase()}?pretty' -H 'Content-Type: application/json' -d '\n${JSON.stringify(mapping, null, 4)}\n'`;
34+
return `curl -XPUT '${host}:${port}/${indexName.toLowerCase()}?pretty${includeTypeName}' -H 'Content-Type: application/json' -d '\n${JSON.stringify(mapping, null, 4)}\n'`;
3335
},
3436

3537
getKibanaScript(mapping, indexData) {
@@ -80,7 +82,15 @@ module.exports = {
8082

8183
this.setProperties(schema, fieldProperties, data);
8284

83-
if (type === 'geo_shape' || type === 'geo_point') {
85+
if (type === 'alias') {
86+
return Object.assign({}, schema, this.getAliasSchema(field, data));
87+
} else if (type === 'join') {
88+
return Object.assign({}, schema, this.getJoinSchema(field));
89+
} else if (
90+
[
91+
'completion', 'sparse_vector', 'dense_vector', 'geo_shape', 'geo_point', 'rank_feature', 'rank_features'
92+
].includes(type)
93+
) {
8494
return schema;
8595
} else if (field.properties) {
8696
schema.properties = this.getSchemaByItem(field.properties, data);
@@ -242,5 +252,55 @@ module.exports = {
242252
}
243253

244254
return false;
255+
},
256+
257+
getJoinSchema(field) {
258+
if (!Array.isArray(field.relations)) {
259+
return {};
260+
}
261+
262+
const relations = field.relations.reduce((result, item) => {
263+
if (!item.parent) {
264+
return result;
265+
}
266+
267+
if (!Array.isArray(item.children)) {
268+
return result;
269+
}
270+
271+
if (item.children.length === 1) {
272+
return Object.assign({}, result, {
273+
[item.parent]: (item.children[0] || {}).name
274+
});
275+
}
276+
277+
return Object.assign({}, result, {
278+
[item.parent]: item.children.map(item => item.name || "")
279+
});
280+
}, {});
281+
282+
return { relations };
283+
},
284+
285+
getAliasSchema(field, data) {
286+
if (!Array.isArray(field.path)) {
287+
return {};
288+
}
289+
290+
if (field.path.length === 0) {
291+
return {};
292+
}
293+
294+
const pathName = schemaHelper.getPathName(
295+
field.path[0].keyId,
296+
[
297+
data.jsonSchema,
298+
data.internalDefinitions,
299+
data.modelDefinitions,
300+
data.externalDefinitions
301+
]
302+
);
303+
304+
return { path: pathName };
245305
}
246306
};

helper/helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const containerLevelConfig = readConfig('../properties_pane/container_level/cont
88

99
module.exports = {
1010
getTargetFieldLevelPropertyNames(type, data) {
11-
if (!fieldLevelConfig.structure[type]) {
11+
if (!fieldLevelConfig.structure[type] || !Array.isArray(fieldLevelConfig.structure[type])) {
1212
return [];
1313
}
1414

helper/schemaHelper.js

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ const getPathById = (schema, id, path) => {
2828
}
2929
};
3030

31-
const getNameByPath = (schema, path, parentName) => {
31+
const getNameByPath = (schema, path) => {
3232
if (schema.properties) {
3333
return Object.keys(schema.properties).reduce((foundedName, propertyName) => {
34-
if (foundedName !== "") {
34+
if (foundedName.length) {
3535
return foundedName;
3636
}
3737

@@ -42,14 +42,16 @@ const getNameByPath = (schema, path, parentName) => {
4242
}
4343

4444
if (path.length === 1) {
45-
return propertyName;
45+
return [ propertyName ];
4646
}
4747

48-
return getNameByPath(property, path.slice(1), propertyName);
49-
}, "");
48+
return [
49+
propertyName, ...getNameByPath(property, path.slice(1))
50+
];
51+
}, []);
5052
} else if (Array.isArray(schema.items)) {
5153
return schema.items.reduce((foundedName, property, i) => {
52-
if (foundedName !== "") {
54+
if (foundedName.length) {
5355
return foundedName;
5456
}
5557

@@ -58,36 +60,74 @@ const getNameByPath = (schema, path, parentName) => {
5860
}
5961

6062
if (path.length === 1) {
61-
return parentName + '[' + i + ']';
63+
return [ '[' + i + ']' ];
6264
}
6365

64-
return getNameByPath(property, path.slice(1), parentName + '[' + i + ']');
65-
}, "");
66+
return [
67+
'[' + i + ']',
68+
...getNameByPath(property, path.slice(1), '[' + i + ']')
69+
];
70+
}, []);
6671
} else if (Object(schema.items) === schema.items) {
6772
const property = schema.items;
6873

6974
if (property.GUID !== path[0]) {
70-
return "";
75+
return [ "" ];
7176
}
7277

7378
if (path.length === 1) {
74-
return parentName + '[0]';
79+
return ['[0]'];
7580
}
7681

77-
return getNameByPath(property, path.slice(1), parentName + '[0]');
82+
return [
83+
'[0]',
84+
...getNameByPath(property, path.slice(1), '[0]')
85+
];
7886
}
7987
};
8088

89+
const joinIndex = (items) => {
90+
return items.reduce((result, item) => {
91+
if (/\[\d+\]/.test(item)) {
92+
return [
93+
...result.slice(0, -1),
94+
result[result.length - 1] + item
95+
];
96+
} else {
97+
return [
98+
...result,
99+
item
100+
];
101+
}
102+
}, []);
103+
};
104+
81105
const findFieldNameById = (id, source) => {
82106
let path = getPathById(source, id, []);
83107

84108
if (path) {
85-
return getNameByPath(source, path, "");
109+
const name = joinIndex(getNameByPath(source, path, ""));
110+
111+
return name[name.length - 1] || "";
86112
} else {
87113
return "";
88114
}
89115
};
90116

117+
const getPathName = (id, sources) => {
118+
for (let i = 0; i < sources.length; i++) {
119+
let path = getPathById(sources[i], id, []);
120+
121+
if (path) {
122+
const name = getNameByPath(sources[i], path, "");
123+
124+
return name.slice(1).filter(item => !/\[\d+\]/.test(item)).join('.');
125+
}
126+
}
127+
128+
return "";
129+
};
130+
91131
const getNamesByIds = (ids, sources) => {
92132
return ids.reduce((names, id) => {
93133
for (let i = 0; i < sources.length; i++) {
@@ -103,5 +143,6 @@ const getNamesByIds = (ids, sources) => {
103143
};
104144

105145
module.exports = {
106-
getNamesByIds
146+
getNamesByIds,
147+
getPathName
107148
};

jsonSchemaProperties.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"unneededFieldProps": ["collectionName", "name", "users", "indexes", "collectionUsers", "additionalPropertieserties", "subTypes"],
2+
"unneededFieldProps": ["collectionName", "name", "users", "indexes", "collectionUsers", "additionalProperties", "subTypes"],
33
"removeIfPropsNegative": ["partitionKey", "sortKey"]
44
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Elasticsearch",
3-
"version": "0.1.19",
4-
"versionDate": "2019-05-03",
3+
"version": "0.1.20",
4+
"versionDate": "2019-05-07",
55
"author": "hackolade",
66
"engines": {
77
"hackolade": "1.12.7",

0 commit comments

Comments
 (0)