Search in sources :

Example 1 with TableMetadata

use of com.datastax.oss.driver.api.core.metadata.schema.TableMetadata in project janusgraph by JanusGraph.

the class CQLStoreManager method getSpeculativeRetry.

@VisibleForTesting
String getSpeculativeRetry(final String name) throws BackendException {
    TableMetadata tableMetadata = getTableMetadata(name);
    Object res = tableMetadata.getOptions().get(CqlIdentifier.fromCql("speculative_retry"));
    return (String) res;
}
Also used : TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) VisibleForTesting(com.datastax.oss.driver.shaded.guava.common.annotations.VisibleForTesting)

Example 2 with TableMetadata

use of com.datastax.oss.driver.api.core.metadata.schema.TableMetadata in project janusgraph by JanusGraph.

the class CQLStoreManager method getGcGraceSeconds.

@VisibleForTesting
Integer getGcGraceSeconds(final String name) throws BackendException {
    TableMetadata tableMetadata = getTableMetadata(name);
    Object gcGraceSeconds = tableMetadata.getOptions().get(CqlIdentifier.fromCql("gc_grace_seconds"));
    return (Integer) gcGraceSeconds;
}
Also used : TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) VisibleForTesting(com.datastax.oss.driver.shaded.guava.common.annotations.VisibleForTesting)

Example 3 with TableMetadata

use of com.datastax.oss.driver.api.core.metadata.schema.TableMetadata in project janusgraph by JanusGraph.

the class CQLStoreManager method getCompressionOptions.

@VisibleForTesting
Map<String, String> getCompressionOptions(final String name) throws BackendException {
    TableMetadata tableMetadata = getTableMetadata(name);
    Object compressionOptions = tableMetadata.getOptions().get(CqlIdentifier.fromCql("compression"));
    return (Map<String, String>) compressionOptions;
}
Also used : TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(io.vavr.collection.HashMap) VisibleForTesting(com.datastax.oss.driver.shaded.guava.common.annotations.VisibleForTesting)

Example 4 with TableMetadata

use of com.datastax.oss.driver.api.core.metadata.schema.TableMetadata in project janusgraph by JanusGraph.

the class CQLStoreTest method testExistTableOpenDatabase.

@Test
public void testExistTableOpenDatabase() throws BackendException {
    // arrange
    String someTableName = "foo";
    Metadata metadata = mock(Metadata.class);
    KeyspaceMetadata keyspaceMetadata = mock(KeyspaceMetadata.class);
    TableMetadata tableMetadata = mock(TableMetadata.class);
    when(keyspaceMetadata.getTable(someTableName)).thenReturn(Optional.of(tableMetadata));
    when(session.getMetadata()).thenReturn(metadata);
    when(metadata.getKeyspace(mockManager.getKeyspaceName())).thenReturn(Optional.of(keyspaceMetadata));
    // act
    mockManager.openDatabase(someTableName, null);
    // assert
    verify(session, never()).execute(any(Statement.class));
}
Also used : TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) Statement(com.datastax.oss.driver.api.core.cql.Statement) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata) Metadata(com.datastax.oss.driver.api.core.metadata.Metadata) TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata) KeyColumnValueStoreTest(org.janusgraph.diskstorage.KeyColumnValueStoreTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with TableMetadata

use of com.datastax.oss.driver.api.core.metadata.schema.TableMetadata in project thingsboard by thingsboard.

the class CassandraDbHelper method loadCf.

public static void loadCf(KeyspaceMetadata ks, GuavaSession session, String cfName, String[] columns, Path sourceFile, boolean parseHeader) throws Exception {
    TableMetadata tableMetadata = ks.getTable(cfName).get();
    PreparedStatement prepared = session.prepare(createInsertStatement(cfName, columns));
    CSVFormat csvFormat = CSV_DUMP_FORMAT;
    if (parseHeader) {
        csvFormat = csvFormat.withFirstRecordAsHeader();
    } else {
        csvFormat = CSV_DUMP_FORMAT.withHeader(columns);
    }
    try (CSVParser csvParser = new CSVParser(Files.newBufferedReader(sourceFile), csvFormat)) {
        csvParser.forEach(record -> {
            BoundStatementBuilder boundStatementBuilder = new BoundStatementBuilder(prepared.bind());
            for (String column : columns) {
                setColumnValue(tableMetadata, column, record, boundStatementBuilder);
            }
            session.execute(boundStatementBuilder.build());
        });
    }
}
Also used : TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) BoundStatementBuilder(com.datastax.oss.driver.api.core.cql.BoundStatementBuilder) CSVParser(org.apache.commons.csv.CSVParser) PreparedStatement(com.datastax.oss.driver.api.core.cql.PreparedStatement) CSVFormat(org.apache.commons.csv.CSVFormat)

Aggregations

TableMetadata (com.datastax.oss.driver.api.core.metadata.schema.TableMetadata)5 VisibleForTesting (com.datastax.oss.driver.shaded.guava.common.annotations.VisibleForTesting)3 BoundStatementBuilder (com.datastax.oss.driver.api.core.cql.BoundStatementBuilder)1 PreparedStatement (com.datastax.oss.driver.api.core.cql.PreparedStatement)1 Statement (com.datastax.oss.driver.api.core.cql.Statement)1 Metadata (com.datastax.oss.driver.api.core.metadata.Metadata)1 KeyspaceMetadata (com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata)1 HashMap (io.vavr.collection.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CSVFormat (org.apache.commons.csv.CSVFormat)1 CSVParser (org.apache.commons.csv.CSVParser)1 KeyColumnValueStoreTest (org.janusgraph.diskstorage.KeyColumnValueStoreTest)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1