From 46ef00a31594312403e8b42e66ae9354e7bf87ef Mon Sep 17 00:00:00 2001 From: Maxwell Guo Date: Fri, 11 Oct 2024 19:23:41 +0800 Subject: [PATCH] Implementation of CEP-43 patch by Maxwell Guo; reviewed by Stefan Miklosovic, Benjamin Lerer for CASSANDRA-19964 --- CHANGES.txt | 1 + NEWS.txt | 2 + doc/cql3/CQL.textile | 33 ++ .../examples/BNF/create_table_like.bnf | 3 + .../examples/CQL/create_table_like.cql | 14 + pylib/cqlshlib/cql3handling.py | 22 + pylib/cqlshlib/test/test_cql_parsing.py | 3 + pylib/cqlshlib/test/test_cqlsh_completion.py | 117 +++- src/antlr/Parser.g | 12 + .../cassandra/audit/AuditLogEntryType.java | 1 + .../statements/schema/CopyTableStatement.java | 220 +++++++ .../schema/CreateTableStatement.java | 23 +- .../test/CreateTableNonDeterministicTest.java | 25 + .../test/metric/TableMetricTest.java | 6 + .../cassandra/audit/AuditLoggerTest.java | 23 + .../cassandra/auth/GrantAndRevokeTest.java | 92 +++ .../cql3/AlterSchemaStatementTest.java | 3 +- .../org/apache/cassandra/cql3/CQLTester.java | 73 +++ .../statements/DescribeStatementTest.java | 62 ++ .../createlike/CreateLikeCqlParseTest.java | 51 ++ .../schema/createlike/CreateLikeTest.java | 557 ++++++++++++++++++ .../createlike/CreateLikeWithSessionTest.java | 71 +++ 22 files changed, 1404 insertions(+), 10 deletions(-) create mode 100644 doc/modules/cassandra/examples/BNF/create_table_like.bnf create mode 100644 doc/modules/cassandra/examples/CQL/create_table_like.cql create mode 100644 src/java/org/apache/cassandra/cql3/statements/schema/CopyTableStatement.java create mode 100644 test/unit/org/apache/cassandra/schema/createlike/CreateLikeCqlParseTest.java create mode 100644 test/unit/org/apache/cassandra/schema/createlike/CreateLikeTest.java create mode 100644 test/unit/org/apache/cassandra/schema/createlike/CreateLikeWithSessionTest.java diff --git a/CHANGES.txt b/CHANGES.txt index ab3b662f6a..02a0be0571 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 5.1 + * Implementation of CEP-43 (CASSANDRA-19964) * Periodically disconnect roles that are revoked or have LOGIN=FALSE set (CASSANDRA-19385) * AST library for CQL-based fuzz tests (CASSANDRA-20198) * Support audit logging for JMX operations (CASSANDRA-20128) diff --git a/NEWS.txt b/NEWS.txt index 22921153da..a4cec79660 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -107,6 +107,8 @@ New features JMX to JVM parameters. You have to opt-in to use the configuration via cassandra.yaml by uncommenting the respective configuration sections and by commenting out `configure_jmx` function call in cassandra-env.sh. Enabling both ways of configuring JMX will result in a node failing to start. + - CEP-43 - it is possible to create a table by "copying" as `CREATE TABLE ks.tb_copy LIKE ks.tb;`. + A newly created table will have no data. Upgrading --------- diff --git a/doc/cql3/CQL.textile b/doc/cql3/CQL.textile index 4c2b09acc3..f819ec193d 100644 --- a/doc/cql3/CQL.textile +++ b/doc/cql3/CQL.textile @@ -406,6 +406,39 @@ h4. Other considerations: * When "inserting":#insertStmt / "updating":#updateStmt a given row, not all columns needs to be defined (except for those part of the key), and missing columns occupy no space on disk. Furthermore, adding new columns (see ALTER TABLE) is a constant time operation. There is thus no need to try to anticipate future usage (or to cry when you haven't) when creating a table. +h3(#copyStmt). CREATE TABLE LIKE + +__Syntax:__ + +bc(syntax).. + ::= CREATE ( TABLE | COLUMNFAMILY ) ( IF NOT EXISTS )? LIKE + ( WITH