This is an automated email from the ASF dual-hosted git repository.

smiklosovic pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git

commit 290bd0d337dfc1d669344ec4b59098db79ef9b04
Merge: f650908648 d7917a5144
Author: Stefan Miklosovic <[email protected]>
AuthorDate: Thu May 11 15:59:14 2023 +0200

    Merge branch 'cassandra-4.1' into trunk

 CHANGES.txt                                        |   1 +
 .../cassandra/cql3/functions/UDAggregate.java      |   4 +-
 .../org/apache/cassandra/db/marshal/UserType.java  |   2 +-
 .../cql3/statements/DescribeStatementTest.java     | 130 +++++++++++++++++++++
 4 files changed, 134 insertions(+), 3 deletions(-)

diff --cc CHANGES.txt
index abeb753658,52510028bf..e495dda4f2
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@@ -143,6 -6,8 +143,7 @@@
   * Fix COPY ... TO STDOUT behavior in cqlsh (CASSANDRA-18353)
   * Remove six and Py2SaferScanner merge cruft (CASSANDRA-18354)
  Merged from 4.0:
+  * Fix quoting in toCqlString methods of UDTs and aggregates (CASSANDRA-17918)
 - * NPE when deserializing malformed collections from client (CASSANDRA-18505)
   * Improve 'Not enough space for compaction' logging messages 
(CASSANDRA-18260)
   * Incremental repairs fail on mixed IPv4/v6 addresses serializing 
SyncRequest (CASSANDRA-18474)
   * Deadlock updating sstable metadata if disk boundaries need reloading 
(CASSANDRA-18443)
diff --cc 
test/unit/org/apache/cassandra/cql3/statements/DescribeStatementTest.java
index 6bf7008a69,52bb3c3d5e..422fcd4cdc
--- a/test/unit/org/apache/cassandra/cql3/statements/DescribeStatementTest.java
+++ b/test/unit/org/apache/cassandra/cql3/statements/DescribeStatementTest.java
@@@ -759,56 -789,104 +791,154 @@@ public class DescribeStatementTest exte
                        row(KEYSPACE_PER_TEST, "index", indexWithOptions, 
expectedIndexStmtWithOptions));
      }
  
 +    @Test
 +    public void testDescribeTableWithColumnMasks() throws Throwable
 +    {
 +        requireNetwork();
 +        DatabaseDescriptor.setDynamicDataMaskingEnabled(true);
 +
 +        String table = createTable(KEYSPACE_PER_TEST,
 +                                   "CREATE TABLE %s (" +
 +                                   "  pk1 text, " +
 +                                   "  pk2 int MASKED WITH DEFAULT, " +
 +                                   "  ck1 int, " +
 +                                   "  ck2 int MASKED WITH mask_default()," +
 +                                   "  s1 decimal static, " +
 +                                   "  s2 decimal static MASKED WITH 
mask_null(), " +
 +                                   "  v1 text, " +
 +                                   "  v2 text MASKED WITH mask_inner(1, 
null), " +
 +                                   "PRIMARY KEY ((pk1, pk2), ck1, ck2 ))");
 +
 +        TableMetadata tableMetadata = 
Schema.instance.getTableMetadata(KEYSPACE_PER_TEST, table);
 +        assertNotNull(tableMetadata);
 +
 +        String tableCreateStatement = "CREATE TABLE " + KEYSPACE_PER_TEST + 
"." + table + " (\n" +
 +                                      "    pk1 text,\n" +
 +                                      "    pk2 int MASKED WITH 
system.mask_default(),\n" +
 +                                      "    ck1 int,\n" +
 +                                      "    ck2 int MASKED WITH 
system.mask_default(),\n" +
 +                                      "    s1 decimal static,\n" +
 +                                      "    s2 decimal static MASKED WITH 
system.mask_null(),\n" +
 +                                      "    v1 text,\n" +
 +                                      "    v2 text MASKED WITH 
system.mask_inner(1, null),\n" +
 +                                      "    PRIMARY KEY ((pk1, pk2), ck1, 
ck2)\n" +
 +                                      ") WITH ID = " + tableMetadata.id + 
"\n" +
 +                                      "    AND CLUSTERING ORDER BY (ck1 ASC, 
ck2 ASC)\n" +
 +                                      "    AND " + tableParametersCql();
 +
 +        assertRowsNet(executeDescribeNet("DESCRIBE TABLE " + 
KEYSPACE_PER_TEST + "." + table + " WITH INTERNALS"),
 +                      row(KEYSPACE_PER_TEST,
 +                          "table",
 +                          table,
 +                          tableCreateStatement));
 +
 +        // masks should be listed even if DDM is disabled
 +        DatabaseDescriptor.setDynamicDataMaskingEnabled(false);
 +        assertRowsNet(executeDescribeNet("DESCRIBE TABLE " + 
KEYSPACE_PER_TEST + "." + table + " WITH INTERNALS"),
 +                      row(KEYSPACE_PER_TEST,
 +                          "table",
 +                          table,
 +                          tableCreateStatement));
 +    }
 +
+     @Test
+     public void testUsingReservedInCreateType() throws Throwable
+     {
+         String type = createType(KEYSPACE_PER_TEST, "CREATE TYPE %s 
(\"token\" text, \"desc\" text);");
+         assertRowsNet(executeDescribeNet(KEYSPACE_PER_TEST, "DESCRIBE TYPE " 
+ type),
+                       row(KEYSPACE_PER_TEST, "type", type, "CREATE TYPE " + 
KEYSPACE_PER_TEST + "." + type + " (\n" +
+                                                            "    \"token\" 
text,\n" +
+                                                            "    \"desc\" 
text\n" +
+                                                            ");"));
+     }
+ 
+     @Test
+     public void testDescMaterializedViewShouldNotOmitQuotations() throws 
Throwable
+     {
+         try{
+             execute("CREATE KEYSPACE testWithKeywords WITH REPLICATION = 
{'class' : 'SimpleStrategy', 'replication_factor' : 1};");
+             execute("CREATE TABLE testWithKeywords.users_mv (username 
varchar, password varchar, gender varchar, session_token varchar, " +
+                     "state varchar, birth_year bigint, \"token\" text, 
PRIMARY KEY (\"token\"));");
+             execute("CREATE MATERIALIZED VIEW testWithKeywords.users_by_state 
AS SELECT * FROM testWithKeywords.users_mv " +
+                     "WHERE STATE IS NOT NULL AND \"token\" IS NOT NULL 
PRIMARY KEY (state, \"token\")");
+ 
+             final String expectedOutput = "CREATE MATERIALIZED VIEW 
testwithkeywords.users_by_state AS\n" +
+                                           "    SELECT *\n" +
+                                           "    FROM 
testwithkeywords.users_mv\n" +
+                                           "    WHERE state IS NOT NULL AND 
\"token\" IS NOT NULL\n" +
+                                           "    PRIMARY KEY (state, 
\"token\")\n" +
+                                           " WITH CLUSTERING ORDER BY 
(\"token\" ASC)\n" +
+                                           "    AND " + mvParametersCql();
+ 
+             testDescribeMaterializedView("testWithKeywords", 
"users_by_state", row("testwithkeywords", "materialized_view", 
"users_by_state", expectedOutput));
+         }
+         finally
+         {
+             execute("DROP KEYSPACE IF EXISTS testWithKeywords");
+         }
+     }
+ 
+     @Test
+     public void testDescFunctionAndAggregateShouldNotOmitQuotations() throws 
Throwable
+     {
+ 
+         final String functionName = KEYSPACE_PER_TEST + ".\"token\"";
+ 
+         createFunctionOverload(functionName,
+                                              "int, ascii",
+                                              "CREATE FUNCTION " + 
functionName + " (\"token\" int, other_in ascii) " +
+                                              "RETURNS NULL ON NULL INPUT " +
+                                              "RETURNS text " +
+                                              "LANGUAGE java " +
+                                              "AS 'return \"Hello World\";'");
+ 
+         for (String describeKeyword : new String[]{"DESCRIBE", "DESC"})
+         {
+ 
+             assertRowsNet(executeDescribeNet(describeKeyword + " FUNCTION " + 
functionName),
+                           row(KEYSPACE_PER_TEST,
+                               "function",
+                               shortFunctionName(functionName) + "(int, 
ascii)",
+                               "CREATE FUNCTION " + functionName + "(\"token\" 
int, other_in ascii)\n" +
+                               "    RETURNS NULL ON NULL INPUT\n" +
+                               "    RETURNS text\n" +
+                               "    LANGUAGE java\n" +
+                               "    AS $$return \"Hello World\";$$;"));
+         }
+ 
+         final String aggregationFunctionName = KEYSPACE_PER_TEST + 
".\"token\"";
+         final String aggregationName = KEYSPACE_PER_TEST + ".\"token\"";
+         createFunctionOverload(aggregationName,
+                                           "int, int",
+                                           "CREATE FUNCTION " + 
aggregationFunctionName + " (\"token\" int, add_to int) " +
+                                           "CALLED ON NULL INPUT " +
+                                           "RETURNS int " +
+                                           "LANGUAGE java " +
+                                           "AS 'return token + add_to;'");
+ 
+ 
+         String aggregate = createAggregate(KEYSPACE_PER_TEST,
+                                                    "int",
+                                                    format("CREATE AGGREGATE 
%%s(int) " +
+                                                           "SFUNC %s " +
+                                                           "STYPE int " +
+                                                           "INITCOND 42",
+                                                           
shortFunctionName(aggregationFunctionName)));
+ 
+ 
+         for (String describeKeyword : new String[]{"DESCRIBE", "DESC"})
+         {
+             assertRowsNet(executeDescribeNet(describeKeyword + " AGGREGATE " 
+ aggregate),
+                           row(KEYSPACE_PER_TEST,
+                               "aggregate",
+                               shortFunctionName(aggregate) + "(int)",
+                               "CREATE AGGREGATE " + aggregate + "(int)\n" +
+                               "    SFUNC " + 
shortFunctionName(aggregationName) + "\n" +
+                               "    STYPE int\n" +
+                               "    INITCOND 42;"));
+         }
+     }
+ 
      private static String allTypesTable()
      {
          return "CREATE TABLE test.has_all_types (\n" +


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to