Skip to content

Commit

Permalink
[#3893] YCQL: Align 2 system_schema.* tables with Cassandra
Browse files Browse the repository at this point in the history
Summary:
Original fix: neonforge-forks@e775a10

The fix updates the schema for 2 virtual (always empty) YCQL tables:
1. Table `system_schema.functions`:
  - Added field `body` (type TEXT).
  - `argument_types` is now a FROZEN LIST of TEXT.
  - Added `argument_types` to the primary key.
  - `argument_names` is now a FROZEN LIST of TEXT.

2. Table `system_schema.aggregates`:
  - `argument_types` is now a FROZEN LIST of TEXT.
  - Added `argument_types` to the primary key.
  - Added field `return_type` (type TEXT).

Test Plan:
./yb_build.sh --java-test org.yb.cql.TestSystemTables#testSystemTableColumns
./yb_build.sh --java-test org.yb.cql.TestSystemTables#testEmptySystemTables

Reviewers: mihnea, stiwary, skumar

Reviewed By: stiwary

Subscribers: smishra, ybase, yql

Differential Revision: https://phorge.dev.yugabyte.com/D37909
  • Loading branch information
OlegLoginov committed Sep 11, 2024
1 parent c89356c commit 7fc3b76
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 11 deletions.
64 changes: 61 additions & 3 deletions java/yb-cql/src/test/java/org/yb/cql/TestSystemTables.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,53 @@ public void testEmptySystemTables() throws Exception {
assertEquals(0, session.execute("SELECT * FROM system_schema.views;").all().size());
}

@Test
public void testSystemTableColumns() throws Exception {
// Table system_schema.aggregates
List<Row> results = session.execute("SELECT * FROM system_schema.columns WHERE " +
"keyspace_name = 'system_schema' AND table_name = 'aggregates'").all();
assertEquals(8, results.size());
verifyColumnSchema(results.get(0), "system_schema", "aggregates",
"keyspace_name", "partition_key", 0, "text", "none");
verifyColumnSchema(results.get(1), "system_schema", "aggregates",
"aggregate_name", "clustering", 0, "text", "asc");
verifyColumnSchema(results.get(2), "system_schema", "aggregates",
"argument_types", "clustering", 1, "frozen<list<text>>", "asc");
verifyColumnSchema(results.get(3), "system_schema", "aggregates",
"final_func", "regular", -1, "text", "none");
verifyColumnSchema(results.get(4), "system_schema", "aggregates",
"initcond", "regular", -1, "text", "none");
verifyColumnSchema(results.get(5), "system_schema", "aggregates",
"return_type", "regular", -1, "text", "none");
verifyColumnSchema(results.get(6), "system_schema", "aggregates",
"state_func", "regular", -1, "text", "none");
verifyColumnSchema(results.get(7), "system_schema", "aggregates",
"state_type", "regular", -1, "text", "none");

// Table system_schema.functions
results = session.execute("SELECT * FROM system_schema.columns WHERE " +
"keyspace_name = 'system_schema' AND table_name = 'functions'").all();
assertEquals(8, results.size());
verifyColumnSchema(results.get(0), "system_schema", "functions",
"keyspace_name", "partition_key", 0, "text", "none");
verifyColumnSchema(results.get(1), "system_schema", "functions",
"function_name", "clustering", 0, "text", "asc");
verifyColumnSchema(results.get(2), "system_schema", "functions",
"argument_types", "clustering", 1, "frozen<list<text>>", "asc");
verifyColumnSchema(results.get(3), "system_schema", "functions",
"argument_names", "regular", -1, "frozen<list<text>>", "none");
verifyColumnSchema(results.get(4), "system_schema", "functions",
"body", "regular", -1, "text", "none");
verifyColumnSchema(results.get(5), "system_schema", "functions",
"called_on_null_input", "regular", -1, "boolean", "none");
verifyColumnSchema(results.get(6), "system_schema", "functions",
"language", "regular", -1, "text", "none");
verifyColumnSchema(results.get(7), "system_schema", "functions",
"return_type", "regular", -1, "text", "none");

// TODO: Implement for 'system_schema' tables: indexes, triggers, types, views, etc.
}

private void checkContactPoints(String column, Row row) {
List<InetSocketAddress> contactPoints = miniCluster.getCQLContactPoints();
boolean found = false;
Expand Down Expand Up @@ -405,17 +452,28 @@ public void testSystemKeyspacesAndTables() throws Exception {
assertEquals(UUID.fromString(uuid), results.get(0).getUUID("id"));
}

private void verifyColumnSchema(Row row, String table_name, String column_name, String kind,
int position, String type, String clustering_order) {
assertEquals(DEFAULT_TEST_KEYSPACE, row.getString("keyspace_name"));
private void verifyColumnSchema(Row row, String keyspace_name, String table_name,
String column_name, String kind, int position,
String type, String clustering_order) {
assertEquals(keyspace_name, row.getString("keyspace_name"));
assertEquals(table_name, row.getString("table_name"));
assertEquals(column_name, row.getString("column_name"));
assertEquals(clustering_order, row.getString("clustering_order"));
assertEquals(kind, row.getString("kind"));
// Note: the "position" =
// 0,1,2,3... for a hash-key column: index of the column among the "partition_key" columns
// 0,1,2,3... for a range-key column: index of the column among the "clustering" columns
// -1 for any non-key column
assertEquals(position, row.getInt("position"));
assertEquals(type, row.getString("type"));
}

private void verifyColumnSchema(Row row, String table_name, String column_name, String kind,
int position, String type, String clustering_order) {
verifyColumnSchema(row,
DEFAULT_TEST_KEYSPACE, table_name, column_name, kind, position, type, clustering_order);
}

private void verifyTypeSchema(Row row, String type_name,
List<String> field_names, List<String> field_types) {
assertEquals(DEFAULT_TEST_KEYSPACE, row.getString("keyspace_name"));
Expand Down
6 changes: 3 additions & 3 deletions src/yb/master/yql_aggregates_vtable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ Schema YQLAggregatesVTable::CreateSchema() const {
SchemaBuilder builder;
CHECK_OK(builder.AddHashKeyColumn("keyspace_name", DataType::STRING));
CHECK_OK(builder.AddKeyColumn("aggregate_name", DataType::STRING));
// TODO: argument_types should be part of the primary key, but since we don't support the CQL
// 'frozen' type, we can't have collections in our primary key.
CHECK_OK(builder.AddColumn("argument_types", QLType::CreateTypeList(DataType::STRING)));
CHECK_OK(builder.AddKeyColumn(
"argument_types", QLType::CreateTypeFrozen(QLType::CreateTypeList(DataType::STRING))));
CHECK_OK(builder.AddColumn("final_func", QLType::Create(DataType::STRING)));
CHECK_OK(builder.AddColumn("initcond", QLType::Create(DataType::STRING)));
CHECK_OK(builder.AddColumn("return_type", QLType::Create(DataType::STRING)));
CHECK_OK(builder.AddColumn("state_func", QLType::Create(DataType::STRING)));
CHECK_OK(builder.AddColumn("state_type", QLType::Create(DataType::STRING)));
return builder.Build();
Expand Down
10 changes: 5 additions & 5 deletions src/yb/master/yql_functions_vtable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ Schema YQLFunctionsVTable::CreateSchema() const {
SchemaBuilder builder;
CHECK_OK(builder.AddHashKeyColumn("keyspace_name", DataType::STRING));
CHECK_OK(builder.AddKeyColumn("function_name", DataType::STRING));
// TODO: argument_types should be part of the primary key, but since we don't support the CQL
// 'frozen' type, we can't have collections in our primary key.
CHECK_OK(builder.AddColumn("argument_types", QLType::CreateTypeList(DataType::STRING)));
// TODO: argument_names should be a frozen list.
CHECK_OK(builder.AddColumn("argument_names", QLType::CreateTypeList(DataType::STRING)));
CHECK_OK(builder.AddKeyColumn(
"argument_types", QLType::CreateTypeFrozen(QLType::CreateTypeList(DataType::STRING))));
CHECK_OK(builder.AddColumn(
"argument_names", QLType::CreateTypeFrozen(QLType::CreateTypeList(DataType::STRING))));
CHECK_OK(builder.AddColumn("body", QLType::Create(DataType::STRING)));
CHECK_OK(builder.AddColumn("called_on_null_input", QLType::Create(DataType::BOOL)));
CHECK_OK(builder.AddColumn("language", QLType::Create(DataType::STRING)));
CHECK_OK(builder.AddColumn("return_type", QLType::Create(DataType::STRING)));
Expand Down

0 comments on commit 7fc3b76

Please sign in to comment.