2929
3030import javax .annotation .Nonnull ;
3131import javax .sql .DataSource ;
32+ import java .math .BigDecimal ;
3233import java .sql .Connection ;
3334import java .sql .PreparedStatement ;
3435import java .sql .ResultSet ;
4142import java .util .HashMap ;
4243import java .util .List ;
4344import java .util .Map ;
45+ import java .util .UUID ;
4446import java .util .logging .Logger ;
4547import java .util .stream .Collectors ;
4648import java .util .stream .StreamSupport ;
@@ -81,17 +83,25 @@ private OracleVectorStoreQueryProvider(
8183 prefixForCollectionTables ,
8284 buildSupportedKeyTypes (),
8385 buildSupportedDataTypes (stringTypeMapping , defaultVarcharSize ),
84- buildSupportedVectorTypes (defaultVarcharSize ));
86+ buildSupportedVectorTypes ());
8587 this .collectionsTable = collectionsTable ;
8688 this .objectMapper = objectMapper ;
8789 }
8890
8991 private static HashMap <Class <?>, String > buildSupportedKeyTypes () {
9092 HashMap <Class <?>, String > supportedKeyTypes = new HashMap <>();
91- supportedKeyTypes .put (String .class , "VARCHAR(255)" );
93+ supportedKeyTypes .put (String .class , String .format (OracleDataTypesMapping .STRING_VARCHAR , 255 ));
94+ supportedKeyTypes .put (short .class , OracleDataTypesMapping .SHORT );
95+ supportedKeyTypes .put (Short .class , OracleDataTypesMapping .SHORT );
96+ supportedKeyTypes .put (int .class , OracleDataTypesMapping .INTEGER );
97+ supportedKeyTypes .put (Integer .class , OracleDataTypesMapping .INTEGER );
98+ supportedKeyTypes .put (long .class , OracleDataTypesMapping .LONG );
99+ supportedKeyTypes .put (Long .class , OracleDataTypesMapping .LONG );
100+ supportedKeyTypes .put (UUID .class , OracleDataTypesMapping .UUID );
101+
92102 return supportedKeyTypes ;
93103 }
94- private static Map <Class <?>, String > buildSupportedVectorTypes (int defaultVarCharLength ) {
104+ private static Map <Class <?>, String > buildSupportedVectorTypes () {
95105 HashMap <Class <?>, String > supportedVectorTypes = new HashMap <>();
96106 supportedVectorTypes .put (String .class , "VECTOR(%s)" );
97107 supportedVectorTypes .put (List .class , "VECTOR(%s)" );
@@ -102,22 +112,29 @@ private static Map<Class<?>, String> buildSupportedVectorTypes(int defaultVarCha
102112 private static Map <Class <?>, String > buildSupportedDataTypes (StringTypeMapping stringTypeMapping , int defaultVarCharLength ) {
103113 HashMap <Class <?>, String > supportedDataTypes = new HashMap <>();
104114 if (stringTypeMapping .equals (StringTypeMapping .USE_VARCHAR )) {
105- supportedDataTypes .put (String .class , "VARCHAR(" + defaultVarCharLength + ")" );
115+ supportedDataTypes .put (String .class , String . format ( OracleDataTypesMapping . STRING_VARCHAR , defaultVarCharLength ) );
106116 } else {
107- supportedDataTypes .put (String .class , "CLOB" );
117+ supportedDataTypes .put (String .class , OracleDataTypesMapping . STRING_CLOB );
108118 }
109- supportedDataTypes .put (Integer .class , "INTEGER" );
110- supportedDataTypes .put (int .class , "INTEGER" );
111- supportedDataTypes .put (Long .class , "LONG" );
112- supportedDataTypes .put (long .class , "LONG" );
113- supportedDataTypes .put (Float .class , "REAL" );
114- supportedDataTypes .put (float .class , "REAL" );
115- supportedDataTypes .put (Double .class , "DOUBLE PRECISION" );
116- supportedDataTypes .put (double .class , "DOUBLE PRECISION" );
117- supportedDataTypes .put (Boolean .class , "BOOLEAN" );
118- supportedDataTypes .put (boolean .class , "BOOLEAN" );
119- supportedDataTypes .put (OffsetDateTime .class , "TIMESTAMPTZ" );
120- supportedDataTypes .put (List .class , "JSON" );
119+ supportedDataTypes .put (byte .class , OracleDataTypesMapping .BYTE );
120+ supportedDataTypes .put (Byte .class , OracleDataTypesMapping .BYTE );
121+ supportedDataTypes .put (short .class , OracleDataTypesMapping .SHORT );
122+ supportedDataTypes .put (Short .class , OracleDataTypesMapping .SHORT );
123+ supportedDataTypes .put (int .class , OracleDataTypesMapping .INTEGER );
124+ supportedDataTypes .put (Integer .class , OracleDataTypesMapping .INTEGER );
125+ supportedDataTypes .put (long .class , OracleDataTypesMapping .LONG );
126+ supportedDataTypes .put (Long .class , OracleDataTypesMapping .LONG );
127+ supportedDataTypes .put (Float .class , OracleDataTypesMapping .FLOAT );
128+ supportedDataTypes .put (float .class , OracleDataTypesMapping .FLOAT );
129+ supportedDataTypes .put (Double .class , OracleDataTypesMapping .DOUBLE );
130+ supportedDataTypes .put (double .class , OracleDataTypesMapping .DOUBLE );
131+ supportedDataTypes .put (BigDecimal .class , OracleDataTypesMapping .DECIMAL );
132+ supportedDataTypes .put (Boolean .class , OracleDataTypesMapping .BOOLEAN );
133+ supportedDataTypes .put (boolean .class , OracleDataTypesMapping .BOOLEAN );
134+ supportedDataTypes .put (OffsetDateTime .class , OracleDataTypesMapping .OFFSET_DATE_TIME );
135+ supportedDataTypes .put (UUID .class , OracleDataTypesMapping .UUID );
136+ supportedDataTypes .put (byte [].class , OracleDataTypesMapping .BYTE_ARRAY );
137+ supportedDataTypes .put (List .class , OracleDataTypesMapping .JSON );
121138 return supportedDataTypes ;
122139 }
123140
@@ -178,11 +195,11 @@ public void createCollection(String collectionName,
178195
179196 List <VectorStoreRecordVectorField > vectorFields = recordDefinition .getVectorFields ();
180197 String createStorageTable = formatQuery ("CREATE TABLE IF NOT EXISTS %s ("
181- + "%s VARCHAR(255) PRIMARY KEY, "
198+ + "%s PRIMARY KEY, "
182199 + "%s, "
183200 + "%s)" ,
184201 getCollectionTableName (collectionName ),
185- getKeyColumnName (recordDefinition .getKeyField ()),
202+ getKeyColumnNameAndType (recordDefinition .getKeyField (), getSupportedDataTypes ()),
186203 getColumnNamesAndTypes (new ArrayList <>(recordDefinition .getDataFields ()),
187204 getSupportedDataTypes ()),
188205 getVectorColumnNamesAndTypes (new ArrayList <>(vectorFields ),
@@ -237,6 +254,11 @@ public void createCollection(String collectionName,
237254 }
238255 }
239256
257+ private String getKeyColumnNameAndType (VectorStoreRecordKeyField field , Map <Class <?>, String > types ) {
258+ return validateSQLidentifier (field .getEffectiveStorageName ()) + " "
259+ + types .get (field .getFieldType ());
260+ }
261+
240262 private String createIndexForDataField (String collectionName , VectorStoreRecordDataField dataField ) {
241263 if (supportedDataTypes .get (dataField .getFieldType ()) == "JSON" ) {
242264 String dataFieldIndex = "CREATE MULTIVALUE INDEX %s ON %s t (t.%s.%s)" ;
@@ -545,7 +567,7 @@ public static class Builder
545567 private String prefixForCollectionTables = DEFAULT_PREFIX_FOR_COLLECTION_TABLES ;
546568 private ObjectMapper objectMapper = new ObjectMapper ();
547569 private StringTypeMapping stringTypeMapping = StringTypeMapping .USE_VARCHAR ;
548- private int defaultVarcharSize = 4000 ;
570+ private int defaultVarcharSize = 2000 ;
549571
550572
551573 @ SuppressFBWarnings ("EI_EXPOSE_REP2" )
@@ -594,7 +616,7 @@ public Builder withStringTypeMapping (StringTypeMapping stringTypeMapping) {
594616 /**
595617 * Sets the default size of the VARHCHAR2 fields.
596618 * @param defaultVarcharSize the default size of the VARHCHAR2 fields. By default, the size
597- * is 4000 .
619+ * is 2000 .
598620 * @return then builder
599621 */
600622 public Builder withDefaultVarcharSize (int defaultVarcharSize ) {
0 commit comments