-
Notifications
You must be signed in to change notification settings - Fork 16
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
List tables command #1510
List tables command #1510
Changes from all commits
42d0fb5
c016640
d590679
aa656ef
02bc38e
24da975
ecabca3
bc30acb
f0cb7bd
550ce05
0a24bd0
5220f57
d94ce09
d47be3a
2683c66
e7e92cb
78ba059
366a503
27f3bef
11b589e
6ad43dc
dd2f2cb
5e45661
7483d58
da04424
d6cd08f
9f386d2
fc48d0d
e01992e
df3bfd5
9a2b136
7986177
27b7fa4
b3e7cb1
e42aaa2
e6096a9
3a49f2e
b98a216
e173c80
0ffba5f
8a150e8
f7103aa
57c3c69
6d9de5a
6b6ccc8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.stargate.sgv2.jsonapi.api.model.command.impl; | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeName; | ||
import io.stargate.sgv2.jsonapi.api.model.command.TableOnlyCommand; | ||
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; | ||
import org.eclipse.microprofile.openapi.annotations.media.Schema; | ||
|
||
@Schema(description = "Command that lists all available tables in a namespace.") | ||
@JsonTypeName("listTables") | ||
public record ListTablesCommand(Options options) implements TableOnlyCommand { | ||
public record Options( | ||
@Schema( | ||
description = "include table properties.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo: "include" to "Include" also this is not the most descriptive. is this more truthful ? "When True the schema for the table is returned, when false just the table name" |
||
type = SchemaType.BOOLEAN, | ||
implementation = Boolean.class) | ||
boolean explain) {} | ||
|
||
/** {@inheritDoc} */ | ||
@Override | ||
public CommandName commandName() { | ||
return CommandName.LIST_TABLES; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.stargate.sgv2.jsonapi.api.model.command.serializer; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import io.stargate.sgv2.jsonapi.api.model.command.table.definition.datatype.ColumnType; | ||
import io.stargate.sgv2.jsonapi.api.model.command.table.definition.datatype.ComplexTypes; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Custom serializer to encode the column type to the JSON payload This is required because | ||
* composite and custom column types may need additional properties to be serialized | ||
*/ | ||
public class ColumnDefinitionSerializer extends JsonSerializer<ColumnType> { | ||
|
||
@Override | ||
public void serialize( | ||
ColumnType columnType, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) | ||
throws IOException { | ||
jsonGenerator.writeStartObject(); | ||
jsonGenerator.writeStringField("type", columnType.getApiName()); | ||
if (columnType instanceof ComplexTypes.MapType mt) { | ||
jsonGenerator.writeStringField("keyType", mt.keyTypeName()); | ||
jsonGenerator.writeStringField("valueType", mt.valueTypeName()); | ||
} else if (columnType instanceof ComplexTypes.ListType lt) { | ||
jsonGenerator.writeStringField("valueType", lt.valueTypeName()); | ||
} else if (columnType instanceof ComplexTypes.SetType st) { | ||
jsonGenerator.writeStringField("valueType", st.valueTypeName()); | ||
} else if (columnType instanceof ComplexTypes.VectorType vt) { | ||
jsonGenerator.writeNumberField("dimension", vt.getDimension()); | ||
if (vt.getVectorConfig() != null) | ||
jsonGenerator.writeObjectField("service", vt.getVectorConfig()); | ||
} else if (columnType instanceof ComplexTypes.UnsupportedType ut) { | ||
jsonGenerator.writeObjectField( | ||
"apiSupport", new ApiSupport(false, false, false, ut.cqlFormat())); | ||
} | ||
jsonGenerator.writeEndObject(); | ||
} | ||
|
||
public record ApiSupport( | ||
maheshrajamani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
boolean createTable, boolean insert, boolean read, String cqlDefinition) {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.stargate.sgv2.jsonapi.api.model.command.serializer; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.JsonSerializer; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import io.stargate.sgv2.jsonapi.api.model.command.table.definition.PrimaryKey; | ||
import java.io.IOException; | ||
|
||
/** | ||
* Custom serializer to encode the column type to the JSON payload This is required because | ||
* composite and custom column types may need additional properties to be serialized | ||
*/ | ||
public class OrderingKeysSerializer extends JsonSerializer<PrimaryKey.OrderingKey[]> { | ||
|
||
@Override | ||
public void serialize( | ||
PrimaryKey.OrderingKey[] orderingKeys, | ||
JsonGenerator jsonGenerator, | ||
SerializerProvider serializerProvider) | ||
throws IOException { | ||
jsonGenerator.writeStartObject(); | ||
if (orderingKeys != null) { | ||
for (PrimaryKey.OrderingKey orderingKey : orderingKeys) { | ||
jsonGenerator.writeNumberField( | ||
orderingKey.column(), orderingKey.order() == PrimaryKey.OrderingKey.Order.ASC ? 1 : -1); | ||
} | ||
} | ||
jsonGenerator.writeEndObject(); | ||
} | ||
|
||
/** | ||
* This is used when a unsupported type column is present in a table. How to use this class will | ||
* evolve as different unsupported types are analyzed. | ||
* | ||
* @param createTable | ||
* @param insert | ||
* @param read | ||
* @param cqlDefinition | ||
*/ | ||
private record ApiSupport( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this record here and in ColumnDefinitionSerializer ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added a comment in there, this is just a place holder object to generate |
||
boolean createTable, boolean insert, boolean read, String cqlDefinition) {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
package io.stargate.sgv2.jsonapi.api.model.command.table.definition; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import io.stargate.sgv2.jsonapi.api.model.command.deserializers.PrimaryKeyDeserializer; | ||
import io.stargate.sgv2.jsonapi.api.model.command.serializer.OrderingKeysSerializer; | ||
import jakarta.annotation.Nullable; | ||
import jakarta.validation.constraints.NotNull; | ||
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType; | ||
|
@@ -16,9 +19,15 @@ | |
// implementation = Object.class, | ||
// description = "Represents the table primary key") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we remove the commented out lines now ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eventually these are needed when we go public, why remove them? |
||
public record PrimaryKey( | ||
@NotNull @Schema(description = "Columns that make the partition keys", type = SchemaType.ARRAY) | ||
@NotNull | ||
@Schema(description = "Columns that make the partition keys", type = SchemaType.ARRAY) | ||
@JsonProperty("partitionBy") | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
String[] keys, | ||
@Nullable @Schema(description = "Columns that make the ordering keys", type = SchemaType.ARRAY) | ||
@Nullable | ||
@Schema(description = "Columns that make the ordering keys", type = SchemaType.ARRAY) | ||
@JsonProperty("partitionSort") | ||
@JsonSerialize(using = OrderingKeysSerializer.class) | ||
OrderingKey[] orderingKeys) { | ||
|
||
public record OrderingKey(String column, Order order) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,29 @@ | ||
package io.stargate.sgv2.jsonapi.api.model.command.table.definition.datatype; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import io.stargate.sgv2.jsonapi.api.model.command.deserializers.ColumnDefinitionDeserializer; | ||
import io.stargate.sgv2.jsonapi.api.model.command.impl.VectorizeConfig; | ||
import io.stargate.sgv2.jsonapi.api.model.command.serializer.ColumnDefinitionSerializer; | ||
import io.stargate.sgv2.jsonapi.exception.SchemaException; | ||
import io.stargate.sgv2.jsonapi.service.schema.tables.ApiDataType; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** Interface for column types. This is used to define the type of a column in a table. */ | ||
@JsonDeserialize(using = ColumnDefinitionDeserializer.class) | ||
@JsonSerialize(using = ColumnDefinitionSerializer.class) | ||
public interface ColumnType { | ||
// Returns api data type. | ||
ApiDataType getApiDataType(); | ||
|
||
/* | ||
Returns the name of the column type to be used in the API request. | ||
*/ | ||
default String getApiName() { | ||
maheshrajamani marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return getApiDataType().getApiName(); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why does this list getSupportedTypes() exist seperate to the definitions of the data types we have else where ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no consolidated place to get all supported data types. Error messages needs to be revisited, May be not a good idea to return list of supported types. |
||
static List<String> getSupportedTypes() { | ||
return List.of( | ||
"ascii", | ||
|
@@ -46,42 +56,6 @@ static ColumnType fromString( | |
// TODO: the name of the type should be a part of the ColumnType interface, and use a map for | ||
// the lookup | ||
switch (type) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pls refactor the errors can be better, e.g. the error here :
we know which is missing can we say that in the error ? also, when this makes the recursive call for the collection types, and the key or value type is unknown it will generate an error that is then lost / thrown away and a more generic one returned. another error that can do with more detail:
include the dimension in the error message |
||
case "ascii": | ||
return PrimitiveTypes.ASCII; | ||
case "bigint": | ||
return PrimitiveTypes.BIGINT; | ||
case "blob": | ||
return PrimitiveTypes.BINARY; | ||
case "boolean": | ||
return PrimitiveTypes.BOOLEAN; | ||
case "date": | ||
return PrimitiveTypes.DATE; | ||
case "decimal": | ||
return PrimitiveTypes.DECIMAL; | ||
case "double": | ||
return PrimitiveTypes.DOUBLE; | ||
case "duration": | ||
return PrimitiveTypes.DURATION; | ||
case "float": | ||
return PrimitiveTypes.FLOAT; | ||
case "inet": | ||
return PrimitiveTypes.INET; | ||
case "int": | ||
return PrimitiveTypes.INT; | ||
case "smallint": | ||
return PrimitiveTypes.SMALLINT; | ||
case "text": | ||
return PrimitiveTypes.TEXT; | ||
case "time": | ||
return PrimitiveTypes.TIME; | ||
case "timestamp": | ||
return PrimitiveTypes.TIMESTAMP; | ||
case "tinyint": | ||
return PrimitiveTypes.TINYINT; | ||
case "uuid": | ||
return PrimitiveTypes.UUID; | ||
case "varint": | ||
return PrimitiveTypes.VARINT; | ||
case "map": | ||
{ | ||
if (keyType == null || valueType == null) { | ||
|
@@ -134,6 +108,10 @@ static ColumnType fromString( | |
} | ||
default: | ||
{ | ||
ColumnType columnType = PrimitiveTypes.fromString(type); | ||
if (columnType != null) { | ||
return columnType; | ||
} | ||
Map<String, String> errorMessageFormattingValues = | ||
Map.of( | ||
"type", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,14 @@ public ApiDataType getApiDataType() { | |
(PrimitiveApiDataType) keyType.getApiDataType(), | ||
(PrimitiveApiDataType) valueType.getApiDataType()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This class says :
but it is not an interface |
||
} | ||
|
||
public String keyTypeName() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. recommend this returns the type, not the name, to avoid doing string comparisons , same for similar functions here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is used in serialization for response json where a text value (int, map, etc) are needed. |
||
return keyType.getApiDataType().getApiName(); | ||
} | ||
|
||
public String valueTypeName() { | ||
return valueType.getApiDataType().getApiName(); | ||
} | ||
} | ||
|
||
/** A list type implementation */ | ||
|
@@ -38,6 +46,10 @@ public ListType(ColumnType valueType) { | |
public ApiDataType getApiDataType() { | ||
return new ComplexApiDataType.ListType((PrimitiveApiDataType) valueType.getApiDataType()); | ||
} | ||
|
||
public String valueTypeName() { | ||
return valueType.getApiDataType().getApiName(); | ||
} | ||
} | ||
|
||
/** A set type implementation */ | ||
|
@@ -52,6 +64,10 @@ public SetType(ColumnType valueType) { | |
public ApiDataType getApiDataType() { | ||
return new ComplexApiDataType.SetType((PrimitiveApiDataType) valueType.getApiDataType()); | ||
} | ||
|
||
public String valueTypeName() { | ||
return valueType.getApiDataType().getApiName(); | ||
} | ||
} | ||
|
||
/* Vector type */ | ||
|
@@ -81,4 +97,30 @@ public int getDimension() { | |
return vectorSize; | ||
} | ||
} | ||
|
||
/** | ||
* Unsupported type implementation, returned in response when cql table has unsupported format | ||
* column | ||
*/ | ||
public static class UnsupportedType implements ColumnType { | ||
private final String cqlFormat; | ||
|
||
public UnsupportedType(String cqlFormat) { | ||
this.cqlFormat = cqlFormat; | ||
} | ||
|
||
@Override | ||
public ApiDataType getApiDataType() { | ||
throw new UnsupportedOperationException("Unsupported type"); | ||
} | ||
|
||
@Override | ||
public String getApiName() { | ||
return "UNSUPPORTED"; | ||
} | ||
|
||
public String cqlFormat() { | ||
return cqlFormat; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should say keyspace not namespace