Skip to content

Commit ef036d7

Browse files
committed
Change add index and table
1 parent d489d98 commit ef036d7

File tree

7 files changed

+146
-101
lines changed

7 files changed

+146
-101
lines changed

astra-db-java/src/main/java/com/datastax/astra/client/Database.java

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.datastax.astra.client.model.collections.Document;
3131
import com.datastax.astra.client.model.command.Command;
3232
import com.datastax.astra.client.model.command.CommandOptions;
33+
import com.datastax.astra.client.model.tables.TableDefinition;
3334
import com.datastax.astra.client.model.tables.row.Row;
3435
import com.datastax.astra.client.model.tables.TableDescriptor;
3536
import com.datastax.astra.client.model.tables.TableOptions;
@@ -510,7 +511,7 @@ public <T> Table<T> getTable(String tableName, @NonNull Class<T> rowClass) {
510511
* Gets a table with a specific default document class.
511512
*
512513
* @param tableName
513-
* the name of the table to return
514+
* the name of the table to
514515
* @param rowClass
515516
* the default class to cast any row returned from the database into.
516517
* @param commandOptions
@@ -529,29 +530,35 @@ public <T> Table<T> getTable(String tableName, CommandOptions<?> commandOptions,
529530
/**
530531
* Create a new table with the given description.
531532
*
532-
* @param tableDescriptor
533+
* @param tableName
534+
* the name of the table to create
535+
* @param tableDefinition
533536
* table definition
534537
*/
535-
public Table<Row> createTable(TableDescriptor tableDescriptor) {
536-
return createTable(tableDescriptor, null, commandOptions, Row.class);
538+
public Table<Row> createTable(String tableName, TableDefinition tableDefinition) {
539+
return createTable(tableName, tableDefinition, null, commandOptions, Row.class);
537540
}
538541

539542
/**
540543
* Create a new table with the given description.
541544
*
542-
* @param tableDescriptor
545+
* @param tableName
546+
* the name for the new table to create
547+
* @param tableDefinition
543548
* table definition
544549
* @param options
545550
* collection options
546551
*/
547-
public Table<Row> createTable(TableDescriptor tableDescriptor, TableOptions options) {
548-
return createTable(tableDescriptor, options, commandOptions, Row.class);
552+
public Table<Row> createTable(String tableName, TableDefinition tableDefinition, TableOptions options) {
553+
return createTable(tableName, tableDefinition, options, commandOptions, Row.class);
549554
}
550555

551556
/**
552557
* Create a new table with the given description.
553558
*
554-
* @param tableDescriptor
559+
* @param tableName
560+
* the table name
561+
* @param tableDefinition
555562
* table definition
556563
* @param options
557564
* collection options
@@ -562,13 +569,15 @@ public Table<Row> createTable(TableDescriptor tableDescriptor, TableOptions opti
562569
* @param <T>
563570
* working object for the document
564571
*/
565-
public <T> Table<T> createTable(TableDescriptor tableDescriptor, TableOptions options, Class<T> documentClass) {
566-
return createTable(tableDescriptor, options, commandOptions, documentClass);
572+
public <T> Table<T> createTable(String tableName, TableDefinition tableDefinition, TableOptions options, Class<T> documentClass) {
573+
return createTable(tableName, tableDefinition, options, commandOptions, documentClass);
567574
}
568575

569576
/**
570577
* Create a new collection with the given name.
571578
*
579+
* @param tableName
580+
* the definition for the new table to create
572581
* @param tableDefinition
573582
* the definition for the new table to create
574583
* @param tableOptions
@@ -577,14 +586,16 @@ public <T> Table<T> createTable(TableDescriptor tableDescriptor, TableOptions op
577586
* options to use when using this collection
578587
* @return the collection
579588
*/
580-
public Table<Row> createTable(TableDescriptor tableDefinition, TableOptions tableOptions, CommandOptions<?> commandOptions) {
581-
return createTable(tableDefinition, tableOptions, commandOptions, Row.class);
589+
public Table<Row> createTable(String tableName, TableDefinition tableDefinition, TableOptions tableOptions, CommandOptions<?> commandOptions) {
590+
return createTable(tableName, tableDefinition, tableOptions, commandOptions, Row.class);
582591
}
583592

584593
/**
585594
* Create a new table with the selected options
586595
*
587-
* @param tableDescriptor
596+
* @param tableName
597+
* the definition for the new table to create
598+
* @param tableDefinition
588599
* the definition for the new table to create
589600
* @param tableOptions
590601
* various options for creating the table
@@ -596,18 +607,20 @@ public Table<Row> createTable(TableDescriptor tableDefinition, TableOptions tabl
596607
* working class for the document
597608
* @return the collection
598609
*/
599-
public <T> Table<T> createTable(TableDescriptor tableDescriptor, TableOptions tableOptions, CommandOptions<?> commandOptions, Class<T> rowClass) {
600-
notNull(tableDescriptor, "tableDescriptor");
601-
hasLength(tableDescriptor.getName(), "tablename");
610+
public <T> Table<T> createTable(String tableName, TableDefinition tableDefinition, TableOptions tableOptions, CommandOptions<?> commandOptions, Class<T> rowClass) {
611+
hasLength(tableName, "tableName");
612+
notNull(tableDefinition, "tableDefinition");
602613
notNull(rowClass, "rowClass");
603614
Command createTable = Command
604615
.create("createTable")
605-
.append("name", tableDescriptor.getName())
606-
.append("definition", tableDescriptor.getDefinition())
607-
.append("options", tableOptions);
616+
.append("name", tableName)
617+
.append("definition", tableDefinition);
618+
if (tableOptions != null) {
619+
createTable.append("options", tableOptions);
620+
}
608621
runCommand(createTable, commandOptions);
609-
log.info("Table '" + green("{}") + "' has been created", tableDescriptor.getName());
610-
return getTable(tableDescriptor.getName(), commandOptions, rowClass);
622+
log.info("Table '" + green("{}") + "' has been created", tableName);
623+
return getTable(tableName, commandOptions, rowClass);
611624
}
612625

613626
/**

astra-db-java/src/main/java/com/datastax/astra/client/Table.java

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.datastax.astra.client.model.tables.index.IndexDefinition;
3333
import com.datastax.astra.client.model.tables.index.IndexDescriptor;
3434
import com.datastax.astra.client.model.tables.index.IndexOptions;
35+
import com.datastax.astra.client.model.tables.index.VectorIndexDefinition;
3536
import com.datastax.astra.client.model.tables.index.VectorIndexDescriptor;
3637
import com.datastax.astra.client.model.tables.index.VectorIndexOptions;
3738
import com.datastax.astra.client.model.tables.row.Row;
@@ -211,91 +212,105 @@ protected String getApiEndpoint() {
211212
/**
212213
* Create a new index with the given description.
213214
*
214-
* @param idxDescriptor
215+
* @param idxName
216+
* name of the index
217+
* @param idxDefinition
215218
* definition of the index
216219
*/
217-
public void createIndex(IndexDescriptor idxDescriptor) {
218-
createIndex(idxDescriptor, null, commandOptions);
220+
public void createIndex(String idxName, IndexDefinition idxDefinition) {
221+
createIndex(idxName, idxDefinition, null, commandOptions);
219222
}
220223

221224
/**
222225
* Create a new index with the given description.
223226
*
224-
* @param idxDescriptor
227+
* @param idxName
228+
* name of the index
229+
* @param idxDefinition
225230
* definition of the index
226231
* @param options
227232
* index options
228233
*/
229-
public void createIndex(IndexDescriptor idxDescriptor, IndexOptions options) {
230-
createIndex(idxDescriptor, options, commandOptions);
234+
public void createIndex(String idxName, IndexDefinition idxDefinition, IndexOptions options) {
235+
createIndex(idxName, idxDefinition, options, commandOptions);
231236
}
232237

233238
/**
234239
* Create a new index with the given description.
235240
*
236-
* @param idxDescriptor
241+
* @param idxName
242+
* name of the index
243+
* @param idxDefinition
237244
* definition of the index
238245
* @param idxOptions
239246
* index options
240247
* @param cmd
241248
* override the default command options
242249
*/
243-
public void createIndex(IndexDescriptor idxDescriptor, IndexOptions idxOptions, CommandOptions<?> cmd) {
244-
notNull(idxDescriptor, "idxDescriptor");
245-
notNull(idxDescriptor.getDefinition(), "indexDefinition");
246-
hasLength(idxDescriptor.getName(), "indexName");
250+
public void createIndex(String idxName, IndexDefinition idxDefinition, IndexOptions idxOptions, CommandOptions<?> cmd) {
251+
hasLength(idxName, "indexName");
252+
notNull(idxDefinition, "idxDefinition");
247253
Command createIndexCommand = Command
248254
.create("createIndex")
249-
.append("name", idxDescriptor.getName())
250-
.append("definition", idxDescriptor.getDefinition())
251-
.append("options", idxOptions);
255+
.append("name", idxName)
256+
.append("definition", idxDefinition);
257+
if (idxOptions != null) {
258+
createIndexCommand.append("options", idxOptions);
259+
}
252260
runCommand(createIndexCommand, commandOptions);
253-
log.info("Index '" + green("{}") + "' has been created", idxDescriptor.getName());
261+
log.info("Index '" + green("{}") + "' has been created", idxName);
254262
}
255263

256264
/**
257265
* Create a new index with the given description.
258266
*
259-
* @param idxDescriptor
267+
* @param idxName
268+
* name of the index
269+
* @param idxDefinition
260270
* definition of the index
261271
*/
262-
public void createVectorIndex(VectorIndexDescriptor idxDescriptor) {
263-
createVectorIndex(idxDescriptor, null, commandOptions);
272+
public void createVectorIndex(String idxName, VectorIndexDefinition idxDefinition) {
273+
createVectorIndex(idxName, idxDefinition, null, commandOptions);
264274
}
265275

266276
/**
267277
* Create a new index with the given description.
268278
*
269-
* @param idxDescriptor
279+
* @param idxName
280+
* index name
281+
* @param idxDefinition
270282
* definition of the index
271283
* @param options
272284
* index options
273285
*/
274-
public void createVectorIndex(VectorIndexDescriptor idxDescriptor, VectorIndexOptions options) {
275-
createVectorIndex(idxDescriptor, options, commandOptions);
286+
public void createVectorIndex(String idxName, VectorIndexDefinition idxDefinition, VectorIndexOptions options) {
287+
createVectorIndex(idxName, idxDefinition, options, commandOptions);
276288
}
277289

278290
/**
279291
* Create a new index with the given description.
280292
*
281-
* @param idxDescriptor
293+
* @param idxName
294+
* index name
295+
* @param idxDefinition
282296
* definition of the index
283297
* @param idxOptions
284298
* index options
285299
* @param cmd
286300
* override the default command options
287301
*/
288-
public void createVectorIndex(VectorIndexDescriptor idxDescriptor, VectorIndexOptions idxOptions, CommandOptions<?> cmd) {
289-
notNull(idxDescriptor, "idxDescriptor");
290-
notNull(idxDescriptor.getDefinition(), "indexDefinition");
291-
hasLength(idxDescriptor.getName(), "indexName");
302+
public void createVectorIndex(String idxName, VectorIndexDefinition idxDefinition, VectorIndexOptions idxOptions, CommandOptions<?> cmd) {
303+
hasLength(idxName, "indexName");
304+
notNull(idxDefinition, "idxDefinition");
292305
Command createIndexCommand = Command
293306
.create("createVectorIndex")
294-
.append("name", idxDescriptor.getName())
295-
.append("definition", idxDescriptor.getDefinition())
296-
.append("options", idxOptions);
307+
.append("name", idxName)
308+
.append("definition", idxDefinition);
309+
if (idxOptions != null) {
310+
createIndexCommand.append("options", idxOptions);
311+
}
297312
runCommand(createIndexCommand, commandOptions);
298-
log.info("Vector Index '" + green("{}") + "' has been created", idxDescriptor.getName());
313+
log.info("Vector Index '" + green("{}") + "' has been created",idxName);
299314
}
300315

301316

astra-db-java/src/main/java/com/datastax/astra/client/model/tables/TableDefinition.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ public TableDefinition addColumn(String name, ColumnTypes type) {
5454
return this;
5555
}
5656

57+
public TableDefinition addColumnText(String name) {
58+
return addColumn(name, ColumnTypes.TEXT);
59+
}
60+
61+
public TableDefinition addColumnInt(String name) {
62+
return addColumn(name, ColumnTypes.INT);
63+
}
64+
65+
public TableDefinition addColumnBoolean(String name) {
66+
return addColumn(name, ColumnTypes.BOOLEAN);
67+
}
68+
5769
public TableDefinition addColumnList(String name, ColumnTypes valueType) {
5870
columns.put(name, new ColumnDefinitionList(valueType));
5971
return this;

astra-db-java/src/main/java/com/datastax/astra/client/model/tables/columns/ColumnTypes.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public enum ColumnTypes {
4848
TINYINT("tinyint"),
4949
VARINT("varint"),
5050
UUID("uuid"),
51+
UNSUPPORTED("UNSUPPORTED"),
5152
VECTOR("vector");
5253

5354
@Getter

astra-db-java/src/main/java/com/datastax/astra/client/model/tables/index/VectorIndexDefinition.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ public class VectorIndexDefinition {
1111

1212
String column;
1313

14-
IndexDefinitionOptions options;
14+
VectorIndexDefinitionOptions options;
1515

1616
public VectorIndexDefinition column(String column) {
1717
this.column = column;
1818
return this;
1919
}
2020

21-
public VectorIndexDefinition options(IndexDefinitionOptions options) {
21+
public VectorIndexDefinition options(VectorIndexDefinitionOptions options) {
2222
this.options = options;
2323
return this;
2424
}

astra-db-java/src/test/java/com/datastax/astra/test/integration/AbstractTableITTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,4 @@
1111
public abstract class AbstractTableITTest extends AbstractDataAPITest {
1212

1313

14-
15-
1614
}

0 commit comments

Comments
 (0)