Skip to content

Commit

Permalink
JAVA-1900: Support virtual tables (aka system views) (#1054)
Browse files Browse the repository at this point in the history
* Java-1900 Adding system views
  • Loading branch information
GregBestland committed Jul 30, 2018
1 parent 0df59ac commit 00a4638
Show file tree
Hide file tree
Showing 24 changed files with 509 additions and 42 deletions.
1 change: 1 addition & 0 deletions changelog/README.md
Expand Up @@ -5,6 +5,7 @@
### 4.0.0-beta2 (in progress)

- [improvement] JAVA-1544: Check API compatibility with Revapi
- [new feature] JAVA-1900: Add support for virtual tables

### 4.0.0-beta1

Expand Down
101 changes: 97 additions & 4 deletions core/revapi.json
Expand Up @@ -6,11 +6,104 @@
"filter": {
"packages": {
"regex": true,
"include": [
"com\\.datastax\\.oss\\.driver\\.api\\..*"
]
"exclude": [
"com\\.datastax\\.oss\\.driver\\.internal\\..*",
"com\\.datastax\\.oss\\.driver\\.shaded\\..*"
]
}
}
},
"ignore": [
{
"code": "java.method.addedToInterface",
"new": "method boolean com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata::isVirtual()",
"package": "com.datastax.oss.driver.api.core.metadata.schema",
"classQualifiedName": "com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata",
"classSimpleName": "KeyspaceMetadata",
"methodName": "isVirtual",
"newArchive": "com.datastax.oss:java-driver-core:jar:4.0.0-beta2-SNAPSHOT",
"elementKind": "method",
"justification": "Adding virtual tables"
},
{
"code": "java.method.returnTypeChanged",
"old": "method java.util.UUID com.datastax.oss.driver.api.core.metadata.schema.RelationMetadata::getId()",
"new": "method java.util.Optional<java.util.UUID> com.datastax.oss.driver.api.core.metadata.schema.RelationMetadata::getId()",
"oldType": "java.util.UUID",
"newType": "java.util.Optional<java.util.UUID>",
"package": "com.datastax.oss.driver.api.core.metadata.schema",
"classQualifiedName": "com.datastax.oss.driver.api.core.metadata.schema.RelationMetadata",
"classSimpleName": "RelationMetadata",
"methodName": "getId",
"oldArchive": "com.datastax.oss:java-driver-core:jar:4.0.0-beta1",
"newArchive": "com.datastax.oss:java-driver-core:jar:4.0.0-beta2-SNAPSHOT",
"elementKind": "method",
"justification": "Adding virtual tables"
},
{
"code": "java.annotation.removed",
"old": "method java.util.UUID com.datastax.oss.driver.api.core.metadata.schema.RelationMetadata::getId()",
"new": "method java.util.Optional<java.util.UUID> com.datastax.oss.driver.api.core.metadata.schema.RelationMetadata::getId()",
"annotationType": "edu.umd.cs.findbugs.annotations.NonNull",
"annotation": "@edu.umd.cs.findbugs.annotations.NonNull",
"package": "com.datastax.oss.driver.api.core.metadata.schema",
"classQualifiedName": "com.datastax.oss.driver.api.core.metadata.schema.RelationMetadata",
"classSimpleName": "RelationMetadata",
"methodName": "getId",
"oldArchive": "com.datastax.oss:java-driver-core:jar:4.0.0-beta1",
"elementKind": "method",
"justification":"Adding virtual tables"
},
{
"code": "java.annotation.removed",
"old": "method java.util.UUID com.datastax.oss.driver.api.core.metadata.schema.RelationMetadata::getId() @ com.datastax.oss.driver.api.core.metadata.schema.TableMetadata",
"new": "method java.util.Optional<java.util.UUID> com.datastax.oss.driver.api.core.metadata.schema.RelationMetadata::getId() @ com.datastax.oss.driver.api.core.metadata.schema.TableMetadata",
"annotationType": "edu.umd.cs.findbugs.annotations.NonNull",
"annotation": "@edu.umd.cs.findbugs.annotations.NonNull",
"package": "com.datastax.oss.driver.api.core.metadata.schema",
"classQualifiedName": "com.datastax.oss.driver.api.core.metadata.schema.TableMetadata",
"classSimpleName": "TableMetadata",
"methodName": "getId",
"oldArchive": "com.datastax.oss:java-driver-core:jar:4.0.0-beta1",
"elementKind": "method",
"justification": "Adding virtual tables"
},
{
"code": "java.method.addedToInterface",
"new": "method boolean com.datastax.oss.driver.api.core.metadata.schema.TableMetadata::isVirtual()",
"package": "com.datastax.oss.driver.api.core.metadata.schema",
"classQualifiedName": "com.datastax.oss.driver.api.core.metadata.schema.TableMetadata",
"classSimpleName": "TableMetadata",
"methodName": "isVirtual",
"newArchive": "com.datastax.oss:java-driver-core:jar:4.0.0-beta2-SNAPSHOT",
"elementKind": "method",
"justification": "Adding virtual tables"
},
{
"code": "java.annotation.removed",
"old": "method java.util.UUID com.datastax.oss.driver.api.core.metadata.schema.RelationMetadata::getId() @ com.datastax.oss.driver.api.core.metadata.schema.ViewMetadata",
"new": "method java.util.Optional<java.util.UUID> com.datastax.oss.driver.api.core.metadata.schema.RelationMetadata::getId() @ com.datastax.oss.driver.api.core.metadata.schema.ViewMetadata",
"annotationType": "edu.umd.cs.findbugs.annotations.NonNull",
"annotation": "@edu.umd.cs.findbugs.annotations.NonNull",
"package": "com.datastax.oss.driver.api.core.metadata.schema",
"classQualifiedName": "com.datastax.oss.driver.api.core.metadata.schema.ViewMetadata",
"classSimpleName": "ViewMetadata",
"methodName": "getId",
"oldArchive": "com.datastax.oss:java-driver-core:jar:4.0.0-beta1",
"elementKind": "method",
"justification": "Adding virtual tables"
},
{
"code": "java.class.externalClassExposedInAPI",
"new": "class com.datastax.oss.driver.api.core.CqlIdentifier",
"classSimpleName": "CqlIdentifier",
"newArchive": "com.datastax.oss:java-driver-core:jar:4.0.0-beta2-SNAPSHOT",
"exampleUseChainInNewApi": "com.datastax.oss.driver.api.core.CqlIdentifier is used as parameter in method com.datastax.oss.driver.api.querybuilder.condition.ConditionBuilder<com.datastax.oss.driver.api.querybuilder.condition.Condition> com.datastax.oss.driver.api.querybuilder.condition.Condition::element(com.datastax.oss.driver.api.core.CqlIdentifier, com.datastax.oss.driver.api.querybuilder.term.Term) (method com.datastax.oss.driver.api.querybuilder.condition.ConditionBuilder<com.datastax.oss.driver.api.querybuilder.condition.Condition> com.datastax.oss.driver.api.querybuilder.condition.Condition::element(com.datastax.oss.driver.api.core.CqlIdentifier, com.datastax.oss.driver.api.querybuilder.term.Term) is part of the API)",
"package": "com.datastax.oss.driver.api.core",
"classQualifiedName": "com.datastax.oss.driver.api.core.CqlIdentifier",
"elementKind": "class",
"justification": "Work around revapi filtering"
}
]
}
}
}
Expand Up @@ -45,6 +45,7 @@ public class Version implements Comparable<Version> {
public static final Version V2_1_0 = parse("2.1.0");
public static final Version V2_2_0 = parse("2.2.0");
public static final Version V3_0_0 = parse("3.0.0");
public static final Version V4_0_0 = parse("4.0.0");

private final int major;
private final int minor;
Expand Down
Expand Up @@ -34,6 +34,9 @@ public interface KeyspaceMetadata extends Describable {
/** Whether durable writes are set on this keyspace. */
boolean isDurableWrites();

/** Whether this keyspace is virtual */
boolean isVirtual();

/** The replication options defined for this keyspace. */
@NonNull
Map<String, String> getReplication();
Expand Down Expand Up @@ -195,13 +198,18 @@ default Optional<? extends AggregateMetadata> getAggregate(
@NonNull
@Override
default String describe(boolean pretty) {
ScriptBuilder builder =
new ScriptBuilder(pretty)
.append("CREATE KEYSPACE ")
.append(getName())
.append(" WITH replication = { 'class' : '")
.append(getReplication().get("class"))
.append("'");
ScriptBuilder builder = new ScriptBuilder(pretty);
if (isVirtual()) {
builder.append("/* VIRTUAL ");
} else {
builder.append("CREATE ");
}
builder
.append("KEYSPACE ")
.append(getName())
.append(" WITH replication = { 'class' : '")
.append(getReplication().get("class"))
.append("'");
for (Map.Entry<String, String> entry : getReplication().entrySet()) {
if (!entry.getKey().equals("class")) {
builder
Expand All @@ -212,11 +220,14 @@ default String describe(boolean pretty) {
.append("'");
}
}
return builder
builder
.append(" } AND durable_writes = ")
.append(Boolean.toString(isDurableWrites()))
.append(";")
.build();
.append(";");
if (isVirtual()) {
builder.append(" */");
}
return builder.build();
}

@NonNull
Expand Down
Expand Up @@ -33,8 +33,7 @@ public interface RelationMetadata extends Describable {
CqlIdentifier getName();

/** The unique id generated by the server for this element. */
@NonNull
UUID getId();
Optional<UUID> getId();

/**
* Convenience method to get all the primary key columns (partition key + clustering columns) in a
Expand Down
Expand Up @@ -26,21 +26,30 @@ public interface TableMetadata extends RelationMetadata {

boolean isCompactStorage();

/** Whether this table is virtual */
boolean isVirtual();

@NonNull
Map<CqlIdentifier, ? extends IndexMetadata> getIndexes();

@NonNull
@Override
default String describe(boolean pretty) {
ScriptBuilder builder =
new ScriptBuilder(pretty)
.append("CREATE TABLE ")
.append(getKeyspace())
.append(".")
.append(getName())
.append(" (")
.newLine()
.increaseIndent();
ScriptBuilder builder = new ScriptBuilder(pretty);
if (isVirtual()) {
builder.append("/* VIRTUAL ");
} else {
builder.append("CREATE ");
}

builder
.append("TABLE ")
.append(getKeyspace())
.append(".")
.append(getName())
.append(" (")
.newLine()
.increaseIndent();

for (ColumnMetadata column : getColumns().values()) {
builder.append(column.getName()).append(" ").append(column.getType().asCql(true, pretty));
Expand Down Expand Up @@ -95,7 +104,11 @@ default String describe(boolean pretty) {
}
Map<CqlIdentifier, Object> options = getOptions();
RelationParser.appendOptions(options, builder);
return builder.append(";").build();
builder.append(";");
if (isVirtual()) {
builder.append(" */");
}
return builder.build();
}

/**
Expand Down
Expand Up @@ -33,6 +33,7 @@ public class DefaultKeyspaceMetadata implements KeyspaceMetadata {

@NonNull private final CqlIdentifier name;
private final boolean durableWrites;
private final boolean virtual;
@NonNull private final Map<String, String> replication;
@NonNull private final Map<CqlIdentifier, UserDefinedType> types;
@NonNull private final Map<CqlIdentifier, TableMetadata> tables;
Expand All @@ -43,6 +44,7 @@ public class DefaultKeyspaceMetadata implements KeyspaceMetadata {
public DefaultKeyspaceMetadata(
@NonNull CqlIdentifier name,
boolean durableWrites,
boolean virtual,
@NonNull Map<String, String> replication,
@NonNull Map<CqlIdentifier, UserDefinedType> types,
@NonNull Map<CqlIdentifier, TableMetadata> tables,
Expand All @@ -51,6 +53,7 @@ public DefaultKeyspaceMetadata(
@NonNull Map<FunctionSignature, AggregateMetadata> aggregates) {
this.name = name;
this.durableWrites = durableWrites;
this.virtual = virtual;
this.replication = replication;
this.types = types;
this.tables = tables;
Expand All @@ -70,6 +73,11 @@ public boolean isDurableWrites() {
return durableWrites;
}

@Override
public boolean isVirtual() {
return virtual;
}

@NonNull
@Override
public Map<String, String> getReplication() {
Expand Down
Expand Up @@ -21,10 +21,7 @@
import com.datastax.oss.driver.api.core.metadata.schema.IndexMetadata;
import com.datastax.oss.driver.api.core.metadata.schema.TableMetadata;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.*;
import net.jcip.annotations.Immutable;

@Immutable
Expand All @@ -34,6 +31,7 @@ public class DefaultTableMetadata implements TableMetadata {
@NonNull private final CqlIdentifier name;
@NonNull private final UUID id;
private final boolean compactStorage;
private final boolean virtual;
@NonNull private final List<ColumnMetadata> partitionKey;
@NonNull private final Map<ColumnMetadata, ClusteringOrder> clusteringColumns;
@NonNull private final Map<CqlIdentifier, ColumnMetadata> columns;
Expand All @@ -43,8 +41,9 @@ public class DefaultTableMetadata implements TableMetadata {
public DefaultTableMetadata(
@NonNull CqlIdentifier keyspace,
@NonNull CqlIdentifier name,
@NonNull UUID id,
UUID id,
boolean compactStorage,
boolean virtual,
@NonNull List<ColumnMetadata> partitionKey,
@NonNull Map<ColumnMetadata, ClusteringOrder> clusteringColumns,
@NonNull Map<CqlIdentifier, ColumnMetadata> columns,
Expand All @@ -54,6 +53,7 @@ public DefaultTableMetadata(
this.name = name;
this.id = id;
this.compactStorage = compactStorage;
this.virtual = virtual;
this.partitionKey = partitionKey;
this.clusteringColumns = clusteringColumns;
this.columns = columns;
Expand All @@ -75,15 +75,20 @@ public CqlIdentifier getName() {

@NonNull
@Override
public UUID getId() {
return id;
public Optional<UUID> getId() {
return Optional.ofNullable(id);
}

@Override
public boolean isCompactStorage() {
return compactStorage;
}

@Override
public boolean isVirtual() {
return virtual;
}

@NonNull
@Override
public List<ColumnMetadata> getPartitionKey() {
Expand Down Expand Up @@ -122,7 +127,7 @@ public boolean equals(Object other) {
TableMetadata that = (TableMetadata) other;
return Objects.equals(this.keyspace, that.getKeyspace())
&& Objects.equals(this.name, that.getName())
&& Objects.equals(this.id, that.getId())
&& Objects.equals(Optional.of(this.id), that.getId())
&& this.compactStorage == that.isCompactStorage()
&& Objects.equals(this.partitionKey, that.getPartitionKey())
&& Objects.equals(this.clusteringColumns, that.getClusteringColumns())
Expand Down
Expand Up @@ -81,8 +81,8 @@ public CqlIdentifier getName() {

@NonNull
@Override
public UUID getId() {
return id;
public Optional<UUID> getId() {
return Optional.of(id);
}

@NonNull
Expand Down Expand Up @@ -137,7 +137,7 @@ public boolean equals(Object other) {
&& Objects.equals(this.baseTable, that.getBaseTable())
&& this.includesAllColumns == that.includesAllColumns()
&& Objects.equals(this.whereClause, that.getWhereClause().orElse(null))
&& Objects.equals(this.id, that.getId())
&& Objects.equals(Optional.of(this.id), that.getId())
&& Objects.equals(this.partitionKey, that.getPartitionKey())
&& Objects.equals(this.clusteringColumns, that.getClusteringColumns())
&& Objects.equals(this.columns, that.getColumns())
Expand Down

0 comments on commit 00a4638

Please sign in to comment.