Search in sources :

Example 31 with AdminRow

use of com.datastax.oss.driver.internal.core.adminrequest.AdminRow in project java-driver by datastax.

the class DseSchemaParser method parse.

@Override
public SchemaRefresh parse() {
    ImmutableMap.Builder<CqlIdentifier, KeyspaceMetadata> keyspacesBuilder = ImmutableMap.builder();
    for (AdminRow row : rows.keyspaces()) {
        DseKeyspaceMetadata keyspace = parseKeyspace(row);
        keyspacesBuilder.put(keyspace.getName(), keyspace);
    }
    for (AdminRow row : rows.virtualKeyspaces()) {
        DseKeyspaceMetadata keyspace = parseVirtualKeyspace(row);
        keyspacesBuilder.put(keyspace.getName(), keyspace);
    }
    SchemaRefresh refresh = new SchemaRefresh(keyspacesBuilder.build());
    LOG.debug("[{}] Schema parsing took {}", logPrefix, NanoTime.formatTimeSince(startTimeNs));
    return refresh;
}
Also used : DseKeyspaceMetadata(com.datastax.dse.driver.api.core.metadata.schema.DseKeyspaceMetadata) DefaultDseKeyspaceMetadata(com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseKeyspaceMetadata) SchemaRefresh(com.datastax.oss.driver.internal.core.metadata.schema.refresh.SchemaRefresh) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) DseKeyspaceMetadata(com.datastax.dse.driver.api.core.metadata.schema.DseKeyspaceMetadata) DefaultDseKeyspaceMetadata(com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseKeyspaceMetadata) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata) AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow) ImmutableMap(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap)

Example 32 with AdminRow

use of com.datastax.oss.driver.internal.core.adminrequest.AdminRow in project java-driver by datastax.

the class DseTableParser method buildVertex.

private DseVertexMetadata buildVertex(CqlIdentifier tableId, Multimap<CqlIdentifier, AdminRow> keyspaceVertices) {
    if (keyspaceVertices == null) {
        return null;
    }
    Collection<AdminRow> tableVertices = keyspaceVertices.get(tableId);
    if (tableVertices == null || tableVertices.isEmpty()) {
        return null;
    }
    AdminRow row = tableVertices.iterator().next();
    return new DefaultDseVertexMetadata(getLabel(row));
}
Also used : AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow) DefaultDseVertexMetadata(com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseVertexMetadata)

Example 33 with AdminRow

use of com.datastax.oss.driver.internal.core.adminrequest.AdminRow in project java-driver by datastax.

the class DseTableParser method buildEdge.

private DseEdgeMetadata buildEdge(CqlIdentifier tableId, Multimap<CqlIdentifier, AdminRow> keyspaceEdges, Multimap<CqlIdentifier, AdminRow> keyspaceVertices) {
    if (keyspaceEdges == null) {
        return null;
    }
    Collection<AdminRow> tableEdges = keyspaceEdges.get(tableId);
    if (tableEdges == null || tableEdges.isEmpty()) {
        return null;
    }
    AdminRow row = tableEdges.iterator().next();
    CqlIdentifier fromTable = CqlIdentifier.fromInternal(row.getString("from_table"));
    CqlIdentifier toTable = CqlIdentifier.fromInternal(row.getString("to_table"));
    return new DefaultDseEdgeMetadata(getLabel(row), fromTable, findVertexLabel(fromTable, keyspaceVertices, "incoming"), CqlIdentifiers.wrapInternal(row.getListOfString("from_partition_key_columns")), CqlIdentifiers.wrapInternal(row.getListOfString("from_clustering_columns")), toTable, findVertexLabel(toTable, keyspaceVertices, "outgoing"), CqlIdentifiers.wrapInternal(row.getListOfString("to_partition_key_columns")), CqlIdentifiers.wrapInternal(row.getListOfString("to_clustering_columns")));
}
Also used : AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) DefaultDseEdgeMetadata(com.datastax.dse.driver.internal.core.metadata.schema.DefaultDseEdgeMetadata)

Example 34 with AdminRow

use of com.datastax.oss.driver.internal.core.adminrequest.AdminRow in project java-driver by datastax.

the class DseTableParser method findVertexLabel.

// system_schema.edges only contains vertex table names. We also expose the labels in our metadata
// objects, so we need to look them up in system_schema.vertices.
private CqlIdentifier findVertexLabel(CqlIdentifier table, Multimap<CqlIdentifier, AdminRow> keyspaceVertices, String directionForErrorMessage) {
    Collection<AdminRow> tableVertices = (keyspaceVertices == null) ? null : keyspaceVertices.get(table);
    if (tableVertices == null || tableVertices.isEmpty()) {
        throw new IllegalArgumentException(String.format("Missing vertex definition for %s table %s", directionForErrorMessage, table.asCql(true)));
    }
    AdminRow row = tableVertices.iterator().next();
    return getLabel(row);
}
Also used : AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow)

Example 35 with AdminRow

use of com.datastax.oss.driver.internal.core.adminrequest.AdminRow in project java-driver by datastax.

the class TableParserTest method should_parse_read_repair_and_additional_write_policy.

/**
 * Covers two additional Cassandra 4.0 options added in JAVA-2090.
 */
@Test
public void should_parse_read_repair_and_additional_write_policy() {
    AdminRow tableRow40 = mockModernTableRow("ks", "foo");
    when(tableRow40.get("read_repair", TypeCodecs.TEXT)).thenReturn("NONE");
    when(tableRow40.get("additional_write_policy", TypeCodecs.TEXT)).thenReturn("40p");
    SchemaRows rows = modernRows(tableRow40, COLUMN_ROWS_3_0, INDEX_ROWS_3_0);
    TableParser parser = new TableParser(rows, context);
    TableMetadata table = parser.parseTable(tableRow40, KEYSPACE_ID, Collections.emptyMap());
    checkTable(table);
    assertThat(table.getOptions()).containsEntry(CqlIdentifier.fromInternal("read_repair"), "NONE").containsEntry(CqlIdentifier.fromInternal("additional_write_policy"), "40p");
}
Also used : TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) AdminRow(com.datastax.oss.driver.internal.core.adminrequest.AdminRow) CassandraSchemaRows(com.datastax.oss.driver.internal.core.metadata.schema.queries.CassandraSchemaRows) SchemaRows(com.datastax.oss.driver.internal.core.metadata.schema.queries.SchemaRows) Test(org.junit.Test)

Aggregations

AdminRow (com.datastax.oss.driver.internal.core.adminrequest.AdminRow)43 Test (org.junit.Test)12 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)7 Optional (java.util.Optional)6 ImmutableMap (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap)5 UnknownHostException (java.net.UnknownHostException)3 UUID (java.util.UUID)3 ClusteringOrder (com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder)2 ColumnMetadata (com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata)2 IndexMetadata (com.datastax.oss.driver.api.core.metadata.schema.IndexMetadata)2 KeyspaceMetadata (com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata)2 TableMetadata (com.datastax.oss.driver.api.core.metadata.schema.TableMetadata)2 DataType (com.datastax.oss.driver.api.core.type.DataType)2 SchemaRefresh (com.datastax.oss.driver.internal.core.metadata.schema.refresh.SchemaRefresh)2 ImmutableList (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 InetSocketAddress (java.net.InetSocketAddress)2 DseColumnMetadata (com.datastax.dse.driver.api.core.metadata.schema.DseColumnMetadata)1 DseIndexMetadata (com.datastax.dse.driver.api.core.metadata.schema.DseIndexMetadata)1 DseKeyspaceMetadata (com.datastax.dse.driver.api.core.metadata.schema.DseKeyspaceMetadata)1