Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HCK-6709: Oracle 23ai: add support for vector data type #100

Merged
merged 12 commits into from
Jun 25, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -124,42 +124,67 @@ module.exports = ({ _, wrap, assignTemplates, templates, commentIfDeactivated, w
return ` INTERVAL DAY${_.isNumber(dayPrecision) ? `(${dayPrecision})` : ''} TO SECOND${_.isNumber(fractSecPrecision) ? `(${fractSecPrecision})` : ''}`;
};

const decorateVector = (type, dimensionNumber, dimensionFormat) => {
const dimension = dimensionNumber || '*';
const format = _.toUpper(dimensionFormat || '*');
return ` ${type}(${dimension}, ${format})`;
};

const canHaveByte = type => ['CHAR', 'VARCHAR2'].includes(type);
const canHaveLength = type => ['CHAR', 'VARCHAR2', 'NCHAR', 'NVARCHAR2', 'RAW', 'UROWID'].includes(type);
const canHavePrecision = type => ['NUMBER', 'FLOAT'].includes(type);
const canHaveScale = type => type === 'NUMBER';
const isIntervalYear = type => type === 'INTERVAL YEAR';
const isIntervalDay = type => type === 'INTERVAL DAY';
const isTimezone = type => type === 'TIMESTAMP';
const isVector = type => type === 'VECTOR';

const decorateType = (type, columnDefinition) => {
switch (true) {
case columnDefinition.lengthSemantics &&
canHaveByte(type) &&
canHaveLength(type) &&
_.isNumber(columnDefinition.length):
return addByteLength(type, columnDefinition.length, columnDefinition.lengthSemantics);
case canHaveLength(type) && _.isNumber(columnDefinition.length):
return addLength(type, columnDefinition.length);
case canHavePrecision(type) && canHaveScale(type):
return addScalePrecision(type, columnDefinition.precision, columnDefinition.scale);
case canHavePrecision(type) && _.isNumber(columnDefinition.precision):
return addPrecision(type, columnDefinition.precision);
case isTimezone(type):
return timestamp(
columnDefinition.fractSecPrecision,
columnDefinition.withTimeZone,
columnDefinition.localTimeZone,
);
case isIntervalYear(type):
return intervalYear(columnDefinition.yearPrecision);
case isIntervalDay(type):
return intervalDay(columnDefinition.dayPrecision, columnDefinition.fractSecPrecision);
case !!(columnDefinition.isUDTRef && columnDefinition.schemaName):
return ` "${columnDefinition.schemaName}"."${type}"`;
default:
return ` ${type}`;
const {
lengthSemantics,
length,
precision,
scale,
fractSecPrecision,
withTimeZone,
localTimeZone,
yearPrecision,
dayPrecision,
isUDTRef,
schemaName,
dimension,
subtype,
} = columnDefinition;

if (lengthSemantics && canHaveByte(type) && canHaveLength(type) && _.isNumber(length)) {
return addByteLength(type, length, lengthSemantics);
}
if (canHaveLength(type) && _.isNumber(length)) {
return addLength(type, length);
}
if (canHavePrecision(type) && canHaveScale(type)) {
return addScalePrecision(type, precision, scale);
}
if (canHavePrecision(type) && _.isNumber(precision)) {
return addPrecision(type, precision);
}
if (isTimezone(type)) {
return timestamp(fractSecPrecision, withTimeZone, localTimeZone);
}
if (isIntervalYear(type)) {
return intervalYear(yearPrecision);
}
if (isIntervalDay(type)) {
return intervalDay(dayPrecision, fractSecPrecision);
}
if (isUDTRef && schemaName) {
return ` "${schemaName}"."${type}"`;
}
if (isVector(type) && (dimension || subtype)) {
return decorateVector(type, dimension, subtype);
}

return ` ${type}`;
};

/**
Expand Down
2 changes: 2 additions & 0 deletions forward_engineering/ddlProvider/ddlProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ module.exports = (baseProvider, options, app) => {
encryption: jsonSchema.encryption,
synonyms: schemaData?.synonyms?.filter(synonym => synonym.synonymEntityId === jsonSchema.GUID) || [],
isUDTRef,
dimension: jsonSchema.dimension,
subtype: jsonSchema.subtype,
...(canHaveIdentity(jsonSchema.mode) && { identity: jsonSchema.identity }),
};
},
Expand Down
48 changes: 48 additions & 0 deletions properties_pane/field_level/fieldLevelConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9797,6 +9797,54 @@ making sure that you maintain a proper JSON format.
"template": "textarea"
}
],
"vector": [
"name",
"code",
"isActivated",
{
"propertyKeyword": "type",
"typeDecorator": {
"value": "vctr",
"useAsTypeName": true
}
},
{
"propertyName": "Dimension",
"propertyKeyword": "dimension",
"propertyType": "numeric",
"valueType": "integer",
"allowNegative": false,
"typeDecorator": {
"useAngleBrackets": true
},
"minValue": 1
},
{
"propertyName": "Subtype",
"propertyKeyword": "subtype",
"shouldValidate": false,
"propertyType": "select",
"typeDecorator": true,
"options": ["", "int8", "float32", "float64"]
},
{
"propertyName": "Comments",
"propertyKeyword": "description",
"propertyTooltip": "comments",
"addTimestampButton": false,
"propertyType": "details",
"template": "textarea"
},
{
"propertyName": "Remarks",
"propertyKeyword": "comments",
"shouldValidate": false,
"propertyTooltip": "remarks",
"addTimestampButton": true,
"propertyType": "details",
"template": "textarea"
}
],
"object_udt": [
{
"fieldKeyword": "name",
Expand Down
3 changes: 2 additions & 1 deletion types/object.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"reference",
"multiple",
"object_udt",
"collection_udt"
"collection_udt",
"vector"
]
}
}
Expand Down
33 changes: 33 additions & 0 deletions types/vector.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "vector",
"erdAbbreviation": "<vctr>",
"dtdAbbreviation": "[...]",
"parentType": "array",
"useSample": false,
"hiddenOnEntity": "view",
"dependency": {
"type": "not",
"values": [
{
"level": "model",
"key": "dbVersion",
"value": "12c"
},
{
"level": "model",
"key": "dbVersion",
"value": "18c"
},
{
"level": "model",
"key": "dbVersion",
"value": "19c"
},
{
"level": "model",
"key": "dbVersion",
"value": "21c"
}
]
}
}