Skip to content

CASSANDRA-14825 Expose schema in virtual table#284

Closed
clohfink wants to merge 6 commits intoapache:trunkfrom
clohfink:describe_vtables
Closed

CASSANDRA-14825 Expose schema in virtual table#284
clohfink wants to merge 6 commits intoapache:trunkfrom
clohfink:describe_vtables

Conversation

@clohfink
Copy link
Contributor

No description provided.

@clohfink clohfink force-pushed the describe_vtables branch 5 times, most recently from 3ec70d0 to 8d6d03c Compare October 16, 2018 14:48
{
AbstractDescribeTable(String keyspace, String name)
{
super(TableMetadata.builder(keyspace, "describe_" + name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given all these tables will have the same schema, I think it might be more easily used if the “type” was just a column, rather than having to go to a whole new table. So you could just “select * from virtual_schema” and get everything.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

complexity there is there are things like having a UDT with same name as a table in the same keyspace. We can have something like ((type), keyspace, name) so that way we can provide uniqueness to everything and it would only be funny for keyspaces.

Copy link
Contributor

@tolbertam tolbertam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried this out and its working great! Had a few suggestions and noticed one issue, but 👍 on the approach.

* limitations under the License.
*/

package org.apache.cassandra.db;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe nitpicking, but should this be in schema package? CQLTypeParser.parseRaw could remain default visibility this way too.

sb.append("\n(this should not be used to reproduce this schema)\n\n");
}

sb.append("CREATE TABLE ");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed previous implementation included IF NOT EXISTS, but only for tables, not other elements. Agree it should be consistent. Was thinking would be kinda nice to have a way of expressing schema with these directives, but not sure of a good way of doing this without duplicating data/complicating things. Probably better that it's done this way, especially since consistent with describe output.

if (metaData.isSuper() || metaData.isVirtual())
return false;

return !(metaData.isCompactTable()
Copy link
Contributor

@tolbertam tolbertam Sep 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since compact storage is not around anymore should be sufficient to use return metaData.isCQLTable() && !metaData.isVirtual(); for this I think.

.kind(TableMetadata.Kind.VIRTUAL)
.partitioner(new LocalPartitioner(utfComposite))
.addPartitionKeyColumn(KEYSPACE, UTF8Type.instance)
.addPartitionKeyColumn(name + "_name", UTF8Type.instance)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if <x>_name was a clustering column so you could do something like select * from system_views.describe_table where keyspace_name='x'


SimpleDataSet result = new SimpleDataSet(metadata());
result.row(keyspace)
.column(CQL, SchemaCQLHelper.getKeyspaceAsCQL(keyspace));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This surfaces a ServerError with an NPE if the keyspace doesn't exist, instead of returning 0 rows:

ERROR [Native-Transport-Requests-1] 2019-09-04 23:05:26,228 QueryMessage.java:124 - Unexpected error during query
java.lang.NullPointerException: null
        at org.apache.cassandra.db.SchemaCQLHelper.toCQL(SchemaCQLHelper.java:152)
        at org.apache.cassandra.db.SchemaCQLHelper.getKeyspaceAsCQL(SchemaCQLHelper.java:65)
        at org.apache.cassandra.db.virtual.DescribeTables$DescribeKeyspaceTable.data(DescribeTables.java:88)

@Override
public DataSet data(DecoratedKey partitionKey)
{
String keyspace = UTF8Type.instance.compose(partitionKey.getKey());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

case CRC_CHECK_CHANCE:
sb.append(tableParams.crcCheckChance);
return;
case DEFAULT_TIME_TO_LIVE:
Copy link
Contributor

@tolbertam tolbertam Sep 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slight exception needed for materialized views in that this should not be included:

cql_from_vt.txt:157:InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot set default_time_to_live for a materialized view. Data in a materialized view always expire at the same time than the corresponding data in the parent table."

@smiklosovic smiklosovic changed the title Expose schema in virtual table for CASSANDRA-14825 CASSANDRA-14825 Expose schema in virtual table Mar 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants