Skip to content

Commit

Permalink
RE and FE of sets, lists, and maps with UDTs
Browse files Browse the repository at this point in the history
  • Loading branch information
pdesmarets committed Mar 29, 2019
1 parent 0b1ff43 commit f5058d3
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 18 deletions.
6 changes: 3 additions & 3 deletions forward_engineering/helpers/typeHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions forward_engineering/helpers/udtHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ const setFrozenForAllUdt = (udtTypeMap) => {
};

const getName = (name, property) => {
if (typeof name === 'number' && property.name) {
return property.name;
}

return property.code || name;
};

Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -26,7 +26,8 @@
"disableMultipleTypes": true,
"disableReverseEngineering": false,
"disableChoices": true,
"enableJsonType": true
"enableJsonType": true,
"enableArrayItemName": true
}
},
"description": "Hackolade plugin for Cassandra Datastax"
Expand Down
2 changes: 2 additions & 0 deletions properties_pane/field_level/fieldLevelConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,8 @@ making sure that you maintain a proper JSON format.
],
"___5": [],
"udt": [
"arrayItemName",
"arrayItemCode",
"name",
"code",
"sampleName",
Expand Down
6 changes: 4 additions & 2 deletions reverse_engineering/cassandraHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 20 additions & 10 deletions reverse_engineering/typesHelper.js
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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 };
};
Expand Down Expand Up @@ -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) => {
Expand All @@ -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
};
};

Expand Down Expand Up @@ -206,24 +211,29 @@ const isTypeEqual = (value, valueData) => {

const getItems = (valueData, sample, udtHash) => {
if (!Array.isArray(sample)) {
return getDefaultItems(valueData);
return getDefaultItems(valueData, udtHash);
}

return sample.map(item => {
return getColumnType(valueData, udtHash, item);
});
};

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 = {
Expand Down

0 comments on commit f5058d3

Please sign in to comment.