Tabnine Logo
SchemaBuilder
Code IndexAdd Tabnine to your IDE (free)

How to use
SchemaBuilder
in
com.datastax.driver.core.schemabuilder

Best Java code snippets using com.datastax.driver.core.schemabuilder.SchemaBuilder (Showing top 20 results out of 315)

origin: Netflix/conductor

private String getCreateTaskLookupTableStatement() {
  return SchemaBuilder.createTable(config.getCassandraKeyspace(), TABLE_TASK_LOOKUP)
      .ifNotExists()
      .addPartitionKey(TASK_ID_KEY, DataType.uuid())
      .addColumn(WORKFLOW_ID_KEY, DataType.uuid())
      .getQueryString();
}
origin: Netflix/conductor

private String getCreateKeyspaceStatement() {
  return SchemaBuilder.createKeyspace(config.getCassandraKeyspace())
      .ifNotExists()
      .with()
      .replication(ImmutableMap.of("class", config.getReplicationStrategy(), config.getReplicationFactorKey(), config.getReplicationFactorValue()))
      .durableWrites(true)
      .getQueryString();
}
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "unit")
public void should_drop_keyspace() throws Exception {
 // When
 SchemaStatement statement = dropKeyspace("test");
 // Then
 assertThat(statement.getQueryString()).isEqualTo("DROP KEYSPACE test");
}
origin: palantir/atlasdb

private CompactionOptions<?> getCompaction(boolean appendHeavyReadLight) {
  return appendHeavyReadLight ? SchemaBuilder.sizedTieredStategy().minThreshold(4).maxThreshold(32)
      : SchemaBuilder.leveledStrategy();
}
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "unit")
public void should_create_table_with_udt_partition_key() throws Exception {
 // When
 SchemaStatement statement = createTable("test").addUDTPartitionKey("u", frozen("user"));
 // Then
 assertThat(statement.getQueryString())
   .isEqualTo("\n\tCREATE TABLE test(\n\t\t" + "u frozen<user>,\n\t\t" + "PRIMARY KEY(u))");
}
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "unit")
public void should_create_key_value_UDT_map_column() throws Exception {
 // When
 SchemaStatement statement =
   createType("ks", "myType")
     .addColumn("col1", DataType.text())
     .addUDTMapColumn("my_udt", frozen("coords"), frozen("address"));
 // Then
 assertThat(statement.getQueryString())
   .isEqualTo(
     "\n\tCREATE TYPE ks.myType(\n\t\t"
       + "col1 text,\n\t\t"
       + "my_udt map<frozen<coords>, frozen<address>>)");
}
origin: com.datastax.cassandra/cassandra-driver-core

  .execute(SchemaBuilder.createKeyspace(keyspace).with().replication(replicationOptions));
   SchemaBuilder.createType("ztype")
     .addColumn("c", DataType.text())
     .addColumn("a", DataType.cint()));
 session.execute(SchemaBuilder.createType("xtype").addColumn("d", DataType.text()));
   SchemaBuilder.createType("ctype")
     .addColumn("\"Z\"", ks.getUserType("ztype").copy(true))
     .addColumn("x", ks.getUserType("xtype").copy(true)));
 session.execute(SchemaBuilder.createType("btype").addColumn("a", DataType.text()));
   SchemaBuilder.createType("atype").addColumn("c", ks.getUserType("ctype").copy(true)));
   SchemaBuilder.createTable("ztable")
     .addPartitionKey("zkey", DataType.text())
     .addColumn("a", ks.getUserType("atype").copy(true))
     .withOptions()
     .compactionOptions(SchemaBuilder.leveledStrategy().ssTableSizeInMB(95)));
} else {
   SchemaBuilder.createTable("ztable")
     .addPartitionKey("zkey", DataType.text())
     .addColumn("a", DataType.cint())
     .withOptions()
     .compactionOptions(SchemaBuilder.leveledStrategy().ssTableSizeInMB(95)));
origin: com.datastax.cassandra/cassandra-driver-core

createTable("test")
  .addPartitionKey("id", DataType.bigint())
  .addClusteringColumn("col1", DataType.uuid())
  .caching(Caching.ROWS_ONLY)
  .comment("This is a comment")
  .compactionOptions(leveledStrategy().ssTableSizeInMB(160))
  .compressionOptions(lz4())
  .dcLocalReadRepairChance(0.21)
  .defaultTimeToLive(100)
  .readRepairChance(0.05)
  .replicateOnWrite(true)
  .speculativeRetry(always())
  .cdc(true);
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "unit")
public void should_create_table_with_speculative_retry_none() throws Exception {
 // When
 SchemaStatement statement =
   createTable("test")
     .addPartitionKey("id", DataType.bigint())
     .addColumn("name", DataType.text())
     .withOptions()
     .speculativeRetry(noSpeculativeRetry());
 // Then
 assertThat(statement.getQueryString())
   .isEqualTo(
     "\n\tCREATE TABLE test(\n\t\t"
       + "id bigint,\n\t\t"
       + "name text,\n\t\t"
       + "PRIMARY KEY(id))\n\t"
       + "WITH speculative_retry = 'NONE'");
}
origin: com.datastax.cassandra/cassandra-driver-core

alterTable("test")
  .withOptions()
  .bloomFilterFPChance(0.01)
  .caching(Caching.ROWS_ONLY)
  .comment("This is a comment")
  .compactionOptions(leveledStrategy().ssTableSizeInMB(160))
  .compressionOptions(lz4())
  .dcLocalReadRepairChance(0.21)
  .defaultTimeToLive(100)
  .replicateOnWrite(true)
  .readRepairChance(0.42)
  .speculativeRetry(always())
  .cdc(true);
alterTable("test").withOptions().caching(KeyCaching.NONE, rows(100));
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_drop_a_table() {
 // Create a table
 session()
   .execute(
     SchemaBuilder.createTable("ks", "DropTable").addPartitionKey("a", DataType.cint()));
 // Drop the table
 session().execute(SchemaBuilder.dropTable("ks", "DropTable"));
 session().execute(SchemaBuilder.dropTable("DropTable").ifExists());
 ResultSet rows =
   session()
     .execute(
       "SELECT columnfamily_name "
         + "FROM system.schema_columnfamilies "
         + "WHERE keyspace_name='ks' AND columnfamily_name='droptable'");
 if (rows.iterator().hasNext()) {
  fail("This table should have been deleted");
 }
}
origin: hugegraph/hugegraph

public void dropTable(CassandraSessionPool.Session session) {
  session.execute(SchemaBuilder.dropTable(this.table).ifExists());
}
origin: com.datastax.cassandra/cassandra-driver-core

session()
  .execute(
    createType(udt).addColumn("first", DataType.text()).addColumn("last", DataType.text()));
UserType userType = cluster().getMetadata().getKeyspace(keyspace).getUserType(udt);
assertThat(userType).isNotNull();
    createTable(table)
      .addPartitionKey("k", DataType.text())
      .addUDTColumn("u", udtLiteral(udt)));
origin: apache/streams

private void createKeyspaceAndTable() {
 Metadata metadata = client.cluster().getMetadata();
 if (Objects.isNull(metadata.getKeyspace(config.getKeyspace()))) {
  LOGGER.info("Keyspace {} does not exist. Creating Keyspace", config.getKeyspace());
  Map<String, Object> replication = new HashMap<>();
  replication.put("class", "SimpleStrategy");
  replication.put("replication_factor", 1);
  String createKeyspaceStmt = SchemaBuilder.createKeyspace(config.getKeyspace()).with()
    .replication(replication).getQueryString();
  client.cluster().connect().execute(createKeyspaceStmt);
 }
 session = client.cluster().connect(config.getKeyspace());
 KeyspaceMetadata ks = metadata.getKeyspace(config.getKeyspace());
 TableMetadata tableMetadata = ks.getTable(config.getTable());
 if (Objects.isNull(tableMetadata)) {
  LOGGER.info("Table {} does not exist in Keyspace {}. Creating Table", config.getTable(), config.getKeyspace());
  String createTableStmt = SchemaBuilder.createTable(config.getTable())
               .addPartitionKey(config.getPartitionKeyColumn(), DataType.varchar())
               .addColumn(config.getColumn(), DataType.blob()).getQueryString();
  session.execute(createTableStmt);
 }
}
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "unit", expectedExceptions = IllegalArgumentException.class)
public void should_fail_when_negative_rows_per_partition() throws Exception {
 createTable("test")
   .addPartitionKey("id", DataType.bigint())
   .addColumn("name", DataType.text())
   .withOptions()
   .caching(KeyCaching.ALL, rows(-3));
}
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "unit", expectedExceptions = IllegalStateException.class)
public void should_fail_when_both_caching_versions() throws Exception {
 createTable("test")
   .addPartitionKey("id", DataType.bigint())
   .addColumn("name", DataType.text())
   .withOptions()
   .caching(Caching.KEYS_ONLY)
   .caching(KeyCaching.ALL, allRows())
   .getQueryString();
}
origin: com.datastax.cassandra/cassandra-driver-core

  .execute(SchemaBuilder.createType("MyUDT").ifNotExists().addColumn("x", DataType.cint()));
UDTType myUDT = UDTType.frozen("MyUDT");
session()
  .execute(
    SchemaBuilder.createTable("ks", "CreateTable")
      .ifNotExists()
      .addPartitionKey("a", DataType.cint())
origin: com.datastax.cassandra/cassandra-driver-core

 @Test(groups = "unit", expectedExceptions = IllegalArgumentException.class)
 public void should_throw_exception_if_tombstone_threshold_negative() throws Exception {
  sizedTieredStategy().bucketLow(0.5).bucketHigh(1.2).coldReadsRatioToOmit(-1.0).build();
 }
}
origin: org.janusgraph/janusgraph-cql

private static CompressionOptions compressionOptions(final Configuration configuration) {
  if (!configuration.get(CF_COMPRESSION)) {
    // No compression
    return noCompression();
  }
  return Match(configuration.get(CF_COMPRESSION_TYPE)).of(
      Case($("LZ4Compressor"), lz4()),
      Case($("SnappyCompressor"), snappy()),
      Case($("DeflateCompressor"), deflate()))
      .withChunkLengthInKb(configuration.get(CF_COMPRESSION_BLOCK_SIZE));
}
origin: org.janusgraph/janusgraph-cql

private static CompactionOptions<?> compactionOptions(final Configuration configuration) {
  if (!configuration.has(COMPACTION_STRATEGY)) {
    return null;
  }
  final CompactionOptions<?> compactionOptions = Match(configuration.get(COMPACTION_STRATEGY))
      .of(
          Case($("SizeTieredCompactionStrategy"), sizedTieredStategy()),
          Case($("DateTieredCompactionStrategy"), dateTieredStrategy()),
          Case($("LeveledCompactionStrategy"), leveledStrategy()));
  Array.of(configuration.get(COMPACTION_OPTIONS))
      .grouped(2)
      .forEach(keyValue -> compactionOptions.freeformOption(keyValue.get(0), keyValue.get(1)));
  return compactionOptions;
}
com.datastax.driver.core.schemabuilderSchemaBuilder

Javadoc

Static methods to build a CQL3 DDL statement.

The provided builders perform very little validation of the built query. There is thus no guarantee that a built query is valid, and it is definitively possible to create invalid queries.

Note that it could be convenient to use an 'import static' to use the methods of this class.

Most used methods

  • createTable
    Start building a new CREATE TABLE statement.
  • createKeyspace
    Start building a new CREATE KEYSPACE statement.
  • dropKeyspace
    Start building a new DROP KEYSPACE statement.
  • dropTable
    Start building a new DROP TABLE statement.
  • leveledStrategy
    Create options for the leveled compaction strategy, to use in a CREATE or ALTER TABLE statement.
  • lz4
    Create options for the LZ4 compression strategy, to use in a CREATE or ALTER TABLE statement.
  • sizedTieredStategy
    Create options for the size-tiered compaction strategy, for use in a CREATE or ALTER TABLE statement
  • createType
    Start building a new CREATE TYPE statement.
  • noSpeculativeRetry
    Create the speculative retry strategy that never retries reads, to use in a CREATE or ALTER TABLE st
  • createIndex
    Start building a new CREATE INDEX statement.
  • dateTieredStrategy
    Create options for the date-tiered compaction strategy, to use in a CREATE or ALTER TABLE statement.
  • deflate
    Create options for the Deflate compression strategy, to use in a CREATE or ALTER TABLE statement.
  • dateTieredStrategy,
  • deflate,
  • dropType,
  • noCompression,
  • snappy,
  • allRows,
  • alterKeyspace,
  • alterTable,
  • always,
  • dropIndex

Popular in Java

  • Making http requests using okhttp
  • runOnUiThread (Activity)
  • notifyDataSetChanged (ArrayAdapter)
  • setScale (BigDecimal)
  • HttpServer (com.sun.net.httpserver)
    This class implements a simple HTTP server. A HttpServer is bound to an IP address and port number a
  • BufferedWriter (java.io)
    Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is
  • FileOutputStream (java.io)
    An output stream that writes bytes to a file. If the output file exists, it can be replaced or appen
  • DecimalFormat (java.text)
    A concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features desig
  • JList (javax.swing)
  • Option (scala)
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now