cassandra-pr mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <>
Subject [GitHub] [cassandra] tolbertam commented on a change in pull request #284: Expose schema in virtual table for CASSANDRA-14825
Date Thu, 05 Sep 2019 06:16:59 GMT
tolbertam commented on a change in pull request #284: Expose schema in virtual table for CASSANDRA-14825

 File path: src/java/org/apache/cassandra/db/virtual/
 @@ -0,0 +1,306 @@
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cassandra.db.virtual;
+import java.nio.ByteBuffer;
+import java.util.Collection;
+import java.util.List;
+import java.util.Optional;
+import org.apache.cassandra.cql3.functions.Function;
+import org.apache.cassandra.cql3.functions.FunctionName;
+import org.apache.cassandra.cql3.functions.UDAggregate;
+import org.apache.cassandra.cql3.functions.UDFunction;
+import org.apache.cassandra.db.DecoratedKey;
+import org.apache.cassandra.db.Keyspace;
+import org.apache.cassandra.db.SchemaCQLHelper;
+import org.apache.cassandra.db.marshal.CompositeType;
+import org.apache.cassandra.db.marshal.UTF8Type;
+import org.apache.cassandra.db.marshal.UserType;
+import org.apache.cassandra.dht.LocalPartitioner;
+import org.apache.cassandra.schema.Functions;
+import org.apache.cassandra.schema.IndexMetadata;
+import org.apache.cassandra.schema.Schema;
+import org.apache.cassandra.schema.TableMetadata;
+import org.apache.cassandra.schema.Types;
+import org.apache.cassandra.schema.ViewMetadata;
+import org.apache.cassandra.utils.ByteBufferUtil;
+public class DescribeTables
+    private static final String KEYSPACE = "keyspace_name";
+    private static final String CQL = "cql";
+    private static final CompositeType utfComposite = CompositeType.getInstance(UTF8Type.instance,
+    public static Collection<VirtualTable> getAll(String name)
+    {
+        return ImmutableList.of(new DescribeKeyspaceTable(name),
+                                new DescribeIndexesTable(name),
+                                new DescribeTypesTable(name),
+                                new DescribeAggregatesTable(name),
+                                new DescribeFunctionsTable(name),
+                                new DescribeViewsTable(name),
+                                new DescribeTablesTable(name));
+    }
+    static final class DescribeKeyspaceTable extends AbstractVirtualTable
+    {
+        DescribeKeyspaceTable(String keyspace)
+        {
+            super(TableMetadata.builder(keyspace, "describe_keyspace")
+                               .comment("cql for keyspace metadata")
+                               .kind(TableMetadata.Kind.VIRTUAL)
+                               .partitioner(new LocalPartitioner(UTF8Type.instance))
+                               .addPartitionKeyColumn(KEYSPACE, UTF8Type.instance)
+                               .addRegularColumn(CQL, UTF8Type.instance)
+                               .build());
+        }
+        @Override
+        public DataSet data(DecoratedKey partitionKey)
+        {
+            String keyspace = UTF8Type.instance.compose(partitionKey.getKey());
 Review comment:
   One thing that popped into my mind is that this requires the internal representation of
the identifier instead of the cql representation.  i.e. if your keyspace name is `"MiXeDCASE"`
to access this you need to query it in an unquoted manner, i.e. `select * from system_views.describe_keyspace
where keyspace_name='MiXeDCASE'`.  
   This is consistent with `system_schema`, but those coming from CQL, or working with quoted
CQL identifiers might be surprised to see that querying with the quoted name, i.e. `'"MiXeDCASE"'`
doesn't work.  That being said I think I like it the way it currently is, primarily for the
consistency with `system_schema` tables.

This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:

With regards,
Apache Git Services

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message