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
64 changes: 64 additions & 0 deletions properties_pane/field_level/fieldLevelConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9797,6 +9797,70 @@ 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": {
"useOptionName": true
},
"options": [
"",
{ "name": "int8", "value": "vector<int8>" },
{ "name": "float32", "value": "vector<float32>" },
{ "name": "float64", "value": "vector<float64>" }
]
},
{
"propertyName": "Not null",
"propertyKeyword": "required",
"propertyType": "checkbox"
},
"minItems",
"maxItems",
"uniqueItems",
"additionalItems",
{
"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
24 changes: 18 additions & 6 deletions properties_pane/model_level/modelLevelConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* Copyright © 2016-2021 by IntegrIT S.A. dba Hackolade. All rights reserved.
*
* The copyright to the computer software herein is the property of IntegrIT S.A.
* The software may be used and/or copied only with the written permission of
* IntegrIT S.A. or in accordance with the terms and conditions stipulated in
* the agreement/contract under which the software has been supplied.
* The software may be used and/or copied only with the written permission of
* IntegrIT S.A. or in accordance with the terms and conditions stipulated in
* the agreement/contract under which the software has been supplied.


In order to define custom properties for any object's properties pane, you may copy/paste from the following,
Expand Down Expand Up @@ -71,8 +71,8 @@ making sure that you maintain a proper JSON format.
]
},
// “groupInput” can have the following states - 0 items, 1 item, and many items.
// “blockInput” has only 2 states - 0 items or 1 item.
// This gives us an easy way to represent it as an object and not as an array internally which is beneficial for processing
// “blockInput” has only 2 states - 0 items or 1 item.
// This gives us an easy way to represent it as an object and not as an array internally which is beneficial for processing
// and forward-engineering in particular.
{
"propertyName": "Block",
Expand Down Expand Up @@ -100,7 +100,7 @@ making sure that you maintain a proper JSON format.
"propertyKeyword": "keyList",
"propertyType": "fieldList",
"template": "orderedList"
},
},
{
"propertyName": "List with attribute",
"propertyKeyword": "keyListOrder",
Expand Down Expand Up @@ -147,6 +147,18 @@ making sure that you maintain a proper JSON format.
]
},
"adapter": "adaptUnavailableTypes"
},
{
"dependency": {
"type": "not",
"values": [
{
"key": "dbVersion",
"value": "23ai"
}
]
},
"adapter": "adaptUnavailableTypes"
}
]
},
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
58 changes: 58 additions & 0 deletions types/vector.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"name": "vector",
"erdAbbreviation": "<vctr>",
"dtdAbbreviation": "[...]",
"parentType": "array",
"useSample": false,
"hiddenOnEntity": "view",
"defaultValues": {
"subtype": "",
"properties": []
},
"subtypes": {
"vector": {
"childValueType": "number"
},
"vector<int8>": {
"childValueType": "number"
},
"vector<float32>": {
"childValueType": "number"
},
"vector<float64>": {
"childValueType": "number"
}
},
"compatibleWith": {
"type": "lobs",
"parentType": "jsonArray",
"mode": "blob",
"subtype": "array",
"properties": []
},
"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"
}
]
}
}