diff --git a/forward_engineering/helpers/typeHelper.js b/forward_engineering/helpers/typeHelper.js index 56be4258..00eccb05 100644 --- a/forward_engineering/helpers/typeHelper.js +++ b/forward_engineering/helpers/typeHelper.js @@ -164,11 +164,11 @@ const getStructuralTypeHandler = (type, isNeedToBeFrozen, udtTypeMap) => { (); }; -const getUDTHandler = (type, udtTypeMap) => { +const getUDTHandler = (type, udtTypeMap, parentIsFrozen) => { return () => { const data = (udtTypeMap[type] || {}); - if (data.frozen) { + if (data.frozen && !parentIsFrozen) { return getFrozen(data.name); } else { return data.name; @@ -197,7 +197,7 @@ const getNestedTypeByData = (propertyData, isNeedToBeFrozen, udtTypeMap, propert const freezingType = ( getStructuralTypeHandler(type, false, udtTypeMap) || - getUDTHandler(type, udtTypeMap) + getUDTHandler(type, udtTypeMap, isNeedToBeFrozen) )(propertyData, propertyName); return (isNeedToBeFrozen) ? getFrozen(freezingType) : freezingType; diff --git a/forward_engineering/helpers/udtHelper.js b/forward_engineering/helpers/udtHelper.js index 0b524f74..eddb2571 100644 --- a/forward_engineering/helpers/udtHelper.js +++ b/forward_engineering/helpers/udtHelper.js @@ -22,6 +22,10 @@ const setFrozenForAllUdt = (udtTypeMap) => { }; const getName = (name, property) => { + if (typeof name === 'number' && property.name) { + return property.name; + } + return property.code || name; }; diff --git a/package.json b/package.json index 6905c561..42feddfb 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "Cassandra", - "version": "0.1.25", - "versionDate": "2019-03-28", + "version": "0.1.26", + "versionDate": "2019-03-29", "author": "hackolade", "engines": { "hackolade": "2.1.x", @@ -26,7 +26,8 @@ "disableMultipleTypes": true, "disableReverseEngineering": false, "disableChoices": true, - "enableJsonType": true + "enableJsonType": true, + "enableArrayItemName": true } }, "description": "Hackolade plugin for Cassandra Datastax" diff --git a/properties_pane/field_level/fieldLevelConfig.json b/properties_pane/field_level/fieldLevelConfig.json index 0aa62dda..e2bf3b7f 100644 --- a/properties_pane/field_level/fieldLevelConfig.json +++ b/properties_pane/field_level/fieldLevelConfig.json @@ -1272,6 +1272,8 @@ making sure that you maintain a proper JSON format. ], "___5": [], "udt": [ + "arrayItemName", + "arrayItemCode", "name", "code", "sampleName", diff --git a/reverse_engineering/cassandraHelper.js b/reverse_engineering/cassandraHelper.js index d83fb6a5..d80ad772 100644 --- a/reverse_engineering/cassandraHelper.js +++ b/reverse_engineering/cassandraHelper.js @@ -239,11 +239,13 @@ const handleUdts = (udts) => { let schema = { properties: {}}; udts.forEach(({ udt, sample }) => { - const name = udt.type.info.name || udt.name; + const info = _.get(udt, 'type.info', _.get(udt, 'info'), {}); + const name = info.name || udt.name; + const fields = info.fields || []; schema.properties[name] = { type: 'udt', static: udt.isStatic, - properties: getTableSchema(udt.type.info.fields, null, sample).properties + properties: getTableSchema(fields, null, sample).properties }; }); return schema; diff --git a/reverse_engineering/typesHelper.js b/reverse_engineering/typesHelper.js index c0783002..902bf47c 100644 --- a/reverse_engineering/typesHelper.js +++ b/reverse_engineering/typesHelper.js @@ -1,9 +1,11 @@ +const _ = require('lodash'); const types = require('cassandra-driver').types; const defaultData = require('../properties_pane/defaultData.json'); const abbrHash = { numeric: 'num', char: 'str', - timestamp: 'st' + timestamp: 'ts', + reference: 'udt' }; const defaultColumnName = defaultData.field.name; @@ -22,7 +24,9 @@ const getColumnType = (column, udtHash, sample) => { }; const getRef = (column) => { - const name = column.type.info.name || column.name; + const name = _.get(column, 'type.info.name', + _.get(column, 'info.name', column.name) + ); return { type: 'reference', $ref: name }; }; @@ -136,7 +140,7 @@ const getSubType = (type, subType) => { const getProperties = (valueData, sample, udtHash) => { if (!sample || typeof sample !== 'object') { - return getDefaultProperties(valueData); + return getDefaultProperties(valueData, udtHash); } return Object.keys(sample).reduce((result, propertyName) => { @@ -146,11 +150,12 @@ const getProperties = (valueData, sample, udtHash) => { }, {}); }; -const getDefaultProperties = (valueData) => { - const handledValueData = getColumnType(valueData); +const getDefaultProperties = (valueData, udtHash) => { + const handledValueData = getColumnType(valueData, udtHash); + const name = handledValueData.$ref || defaultColumnName; return { - [defaultColumnName]: handledValueData + [name]: handledValueData }; }; @@ -206,7 +211,7 @@ const isTypeEqual = (value, valueData) => { const getItems = (valueData, sample, udtHash) => { if (!Array.isArray(sample)) { - return getDefaultItems(valueData); + return getDefaultItems(valueData, udtHash); } return sample.map(item => { @@ -214,16 +219,21 @@ const getItems = (valueData, sample, udtHash) => { }); }; -const getDefaultItems = (valueData) => { - const handledValueData = getColumnType(valueData); +const getDefaultItems = (valueData, udtHash) => { + const handledValueData = getColumnType(valueData, udtHash); return [handledValueData]; }; const getChildTypeByProperties = (properties) => { const key = Object.keys(properties).pop(); + const type = (properties[key] || {}).type; - return (properties[key] || {}).type || 'text'; + if (type) { + return type; + } else { + return 'text'; + } }; module.exports = {