cassandra-pr mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [cassandra] codacy-bot commented on a change in pull request #361: Expose schema via new DESCRIBE CQL statement
Date Mon, 07 Oct 2019 12:23:52 GMT
codacy-bot commented on a change in pull request #361: Expose schema via new DESCRIBE CQL statement
URL: https://github.com/apache/cassandra/pull/361#discussion_r331987667
 
 

 ##########
 File path: src/java/org/apache/cassandra/cql3/statements/DescribeStatement.java
 ##########
 @@ -0,0 +1,1268 @@
+/*
+ * 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
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.cql3.statements;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.UUID;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableList;
+
+import com.googlecode.concurrenttrees.common.Iterables;
+import org.apache.cassandra.audit.AuditLogContext;
+import org.apache.cassandra.audit.AuditLogEntryType;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.cql3.CQLStatement;
+import org.apache.cassandra.cql3.ColumnIdentifier;
+import org.apache.cassandra.cql3.ColumnSpecification;
+import org.apache.cassandra.cql3.QualifiedName;
+import org.apache.cassandra.cql3.QueryOptions;
+import org.apache.cassandra.cql3.ResultSet;
+import org.apache.cassandra.cql3.UTName;
+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.KeyspaceNotDefinedException;
+import org.apache.cassandra.db.SchemaCQLHelper;
+import org.apache.cassandra.db.marshal.UTF8Type;
+import org.apache.cassandra.db.marshal.UserType;
+import org.apache.cassandra.db.virtual.VirtualKeyspaceRegistry;
+import org.apache.cassandra.exceptions.InvalidRequestException;
+import org.apache.cassandra.exceptions.RequestExecutionException;
+import org.apache.cassandra.exceptions.RequestValidationException;
+import org.apache.cassandra.io.util.DataInputBuffer;
+import org.apache.cassandra.io.util.DataOutputBuffer;
+import org.apache.cassandra.schema.IndexMetadata;
+import org.apache.cassandra.schema.KeyspaceMetadata;
+import org.apache.cassandra.schema.Keyspaces;
+import org.apache.cassandra.schema.Schema;
+import org.apache.cassandra.schema.SchemaConstants;
+import org.apache.cassandra.schema.TableMetadata;
+import org.apache.cassandra.service.ClientState;
+import org.apache.cassandra.service.QueryState;
+import org.apache.cassandra.service.StorageService;
+import org.apache.cassandra.service.pager.PagingState;
+import org.apache.cassandra.transport.messages.ResultMessage;
+import org.apache.cassandra.utils.ByteBufferUtil;
+import org.apache.cassandra.utils.FBUtilities;
+import org.apache.cassandra.utils.Pair;
+
+import static java.lang.String.format;
+
+/**
+ * Implements the foundations for all concrete {@code DESCRIBE} statement implementations.
+ *
+ * <p>
+ * Returns a result set that consists of a single column {@code schema_part} of type {@code
text}
+ * and represents a part of the whole {@code DESCRIBE} result.
+ * The get the whole DDL as a single string, the contents of the {@code schema_part} column
of all
+ * rows must be concatenated on the client side. Whitespaces (incl newlines) must not be
inserted
+ * by a client between each rows' {@code schema_part} value as the row separation is arbitrary
and
+ * can happen anywhere in the whole result output.
+ * </p>
+ *
+ * <p>
+ * Paging is implemented to avoid result sets that are too big.
+ * The paging state must not be interpreted on the client side.
+ * Only row-level paging is supported. Byte-level paging will result in an error.
+ * If the schema changes between two pages, the following page will return an error, as the
+ * consistency and correctness of the whole output can no longer be guaranteed.
+ * </p>
+ *
+ * Syntax description (copied from {@code cqlsh}):
+ *
+ * PLEASE KEEP THIS IN SYNC WITH {@code cqlsh.Shell#do_describe} IN {@code bin/cqlsh.py}
+ * AND {@code resources/cassandra/bin/cqlsh.py} !
+ *
+ * <pre><code>
+ *         </code>{@link TheKeyspaces DESCRIBE KEYSPACES}<code>
+ *
+ *           Output the names of all keyspaces.
+ *
+ *         </code>{@link Keyspace DESCRIBE [ONLY] KEYSPACE [&lt;keyspacename&gt;]
[WITH INTERNALS]}<code>
+ *
+ *           Output CQL commands that could be used to recreate the given keyspace,
+ *           and the objects in it (such as tables, types, functions, etc.).
+ *           In some cases, as the CQL interface matures, there will be some metadata
+ *           about a keyspace that is not representable with CQL. That metadata will not
be shown.
+ *
+ *           The '<keyspacename>' argument may be omitted, in which case the current
+ *           keyspace will be described.
+ *
+ *           If WITH INTERNALS is specified, the output contains the table IDs and is
+ *           adopted to represent the DDL necessary to "re-create" dropped columns.
+ *
+ *           If ONLY is specified, only the DDL to recreate the keyspace will be created.
+ *           All keyspace elements, like tables, types, functions, etc will be omitted.
+ *
+ *         </code>{@link Tables DESCRIBE TABLES}<code>
+ *
+ *           Output the names of all tables in the current keyspace, or in all
+ *           keyspaces if there is no current keyspace.
+ *
+ *         </code>{@link Table DESCRIBE TABLE [&lt;keyspace&gt;.]&lt;tablename&gt;
[WITH INTERNALS]}<code>
+ *
+ *           Output CQL commands that could be used to recreate the given table.
+ *           In some cases, as above, there may be table metadata which is not
+ *           representable and which will not be shown.
+ *
+ *           If WITH INTERNALS is specified, the output contains the table ID and is
+ *           adopted to represent the DDL necessary to "re-create" dropped columns.
+ *
+ *         </code>{@link Index DESCRIBE INDEX &lt;indexname&gt;}<code>
+ *
+ *           Output the CQL command that could be used to recreate the given index.
+ *           In some cases, there may be index metadata which is not representable
+ *           and which will not be shown.
+ *
+ *         </code>{@link View DESCRIBE MATERIALIZED VIEW &lt;viewname&gt; [WITH
INTERNALS]}<code>
+ *
+ *           Output the CQL command that could be used to recreate the given materialized
view.
+ *           In some cases, there may be materialized view metadata which is not representable
+ *           and which will not be shown.
+ *
+ *           If WITH INTERNALS is specified, the output contains the table ID and is
+ *           adopted to represent the DDL necessary to "re-create" dropped columns.
+ *
+ *         </code>{@link Cluster DESCRIBE CLUSTER}<code>
+ *
+ *           Output information about the connected Cassandra cluster, such as the
+ *           cluster name, and the partitioner and snitch in use. When you are
+ *           connected to a non-system keyspace, also shows endpoint-range
+ *           ownership information for the Cassandra ring.
+ *
+ *         </code>{@link TheSchema DESCRIBE [FULL] SCHEMA [WITH INTERNALS]}<code>
+ *
+ *           Output CQL commands that could be used to recreate the entire (non-system) schema.
+ *           Works as though "DESCRIBE KEYSPACE k" was invoked for each non-system keyspace
+ *           k. Use DESCRIBE FULL SCHEMA to include the system keyspaces.
+ *
+ *           If WITH INTERNALS is specified, the output contains the table IDs and is
+ *           adopted to represent the DDL necessary to "re-create" dropped columns.
+ *
+ *         </code>{@link Types DESCRIBE TYPES}<code>
+ *
+ *           Output the names of all user-defined-types in the current keyspace, or in all
+ *           keyspaces if there is no current keyspace.
+ *
+ *         </code>{@link Type DESCRIBE TYPE [&lt;keyspace&gt;.]&lt;type&gt;}<code>
+ *
+ *           Output the CQL command that could be used to recreate the given user-defined-type.
+ *
+ *         </code>{@link Functions DESCRIBE FUNCTIONS}<code>
+ *
+ *           Output the names of all user-defined-functions in the current keyspace, or in
all
+ *           keyspaces if there is no current keyspace.
+ *
+ *         </code>{@link Function DESCRIBE FUNCTION [&lt;keyspace&gt;.]&lt;function&gt;}<code>
+ *
+ *           Output the CQL command that could be used to recreate the given user-defined-function.
+ *
+ *         </code>{@link Aggregates DESCRIBE AGGREGATES}<code>
+ *
+ *           Output the names of all user-defined-aggregates in the current keyspace, or
in all
+ *           keyspaces if there is no current keyspace.
+ *
+ *         </code>{@link Aggregate DESCRIBE AGGREGATE [&lt;keyspace&gt;.]&lt;aggregate&gt;}<code>
+ *
+ *           Output the CQL command that could be used to recreate the given user-defined-aggregate.
+ *
+ *         </code>{@link Generic DESCRIBE &lt;objname&gt; [WITH INTERNALS]}<code>
+ *
+ *           Output CQL commands that could be used to recreate the entire object schema,
+ *           where object can be either a keyspace or a table or an index or a materialized
+ *           view (in this order).
+ *
+ *           If WITH INTERNALS is specified and &lt;objname&gt; represents a keyspace,
table
+ *           materialized view, the output contains the table IDs and is
+ *           adopted to represent the DDL necessary to "re-create" dropped columns.
+ *
+ *           &lt;objname&gt; (obviously) cannot be any of the "describe what" qualifiers
like
+ *           "cluster", "table", etc.
+ * </code></pre>
+ */
+public abstract class DescribeStatement extends CQLStatement.Raw implements CQLStatement
+{
+    private static final int LINE_WIDTH = 80;
+
+    private static final String KS = "system";
+    private static final String CF = "describe";
+    private static final List<ColumnSpecification> metadata =
+            ImmutableList.of(new ColumnSpecification(KS, CF, new ColumnIdentifier("schema_part",
true), UTF8Type.instance));
+
+    /**
+     * "Magic version" for the paging state.
+     */
+    private static final int PAGING_STATE_VERSION = 0x0001;
+
+    static final String SCHEMA_CHANGED_WHILE_PAGING_MESSAGE = "The schema has changed since
the previous page of the DESCRIBE statement result. " +
 
 Review comment:
   ![Codacy](https://app.codacy.com/assets/images/favicon.png) Issue found: [Use explicit
scoping instead of the default package private level](https://app.codacy.com/app/Wen1234/cassandra/pullRequest?prid=4274613)

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Mime
View raw message