com.datastax.driver.core.querybuilder.Select.toString()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(17.1k)|赞(0)|评价(0)|浏览(188)

本文整理了Java中com.datastax.driver.core.querybuilder.Select.toString()方法的一些代码示例,展示了Select.toString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Select.toString()方法的具体详情如下:
包路径:com.datastax.driver.core.querybuilder.Select
类名称:Select
方法名:toString

Select.toString介绍

暂无

代码示例

代码示例来源:origin: brianfrankcooper/YCSB

String initialStmt = selectStmt.toString();
StringBuilder scanStmt = new StringBuilder();
scanStmt.append(initialStmt.substring(0, initialStmt.length() - 1));

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

/** @test_category queries:builder */
 @Test(groups = "unit")
 public void should_handle_allow_filtering() {
  assertThat(select().all().from("foo").allowFiltering().toString())
    .isEqualTo("SELECT * FROM foo ALLOW FILTERING;");
  assertThat(select().all().from("foo").where(eq("x", 42)).allowFiltering().toString())
    .isEqualTo("SELECT * FROM foo WHERE x=42 ALLOW FILTERING;");
 }
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "unit")
public void should_handle_to_json() throws Exception {
 assertThat(select().toJson("id").as("id").toJson("age").as("age").from("users").toString())
   .isEqualTo("SELECT toJson(id) AS id,toJson(age) AS age FROM users;");
 assertThat(select().distinct().toJson("id").as("id").from("users").toString())
   .isEqualTo("SELECT DISTINCT toJson(id) AS id FROM users;");
 assertThat(
     select(alias(toJson("id"), "id"), alias(toJson("age"), "age")).from("users").toString())
   .isEqualTo("SELECT toJson(id) AS id,toJson(age) AS age FROM users;");
 assertThat(select(alias(toJson("id"), "id")).distinct().from("users").toString())
   .isEqualTo("SELECT DISTINCT toJson(id) AS id FROM users;");
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "unit")
public void should_handle_select_json() throws Exception {
 assertThat(select().json().from("users").toString()).isEqualTo("SELECT JSON * FROM users;");
 assertThat(select("id", "age").json().from("users").toString())
   .isEqualTo("SELECT JSON id,age FROM users;");
 assertThat(
     select()
       .json()
       .column("id")
       .writeTime("age")
       .ttl("state")
       .as("ttl")
       .from("users")
       .toString())
   .isEqualTo("SELECT JSON id,writetime(age),ttl(state) AS ttl FROM users;");
 assertThat(select().distinct().json().column("id").from("users").toString())
   .isEqualTo(
     "SELECT JSON DISTINCT id FROM users;"); // note that the correct syntax is JSON DISTINCT
}

代码示例来源:origin: otaviojava/Easy-Cassandra

@Override
public String toString() {
  return select.toString();
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "unit")
public void quotingTest() {
 assertEquals(select().from("Metrics", "epochs").toString(), "SELECT * FROM Metrics.epochs;");
 assertEquals(
   select().from("Metrics", quote("epochs")).toString(), "SELECT * FROM Metrics.\"epochs\";");
 assertEquals(
   select().from(quote("Metrics"), "epochs").toString(), "SELECT * FROM \"Metrics\".epochs;");
 assertEquals(
   select().from(quote("Metrics"), quote("epochs")).toString(),
   "SELECT * FROM \"Metrics\".\"epochs\";");
 assertEquals(
   insertInto("Metrics", "epochs").toString(), "INSERT INTO Metrics.epochs () VALUES ();");
 assertEquals(
   insertInto("Metrics", quote("epochs")).toString(),
   "INSERT INTO Metrics.\"epochs\" () VALUES ();");
 assertEquals(
   insertInto(quote("Metrics"), "epochs").toString(),
   "INSERT INTO \"Metrics\".epochs () VALUES ();");
 assertEquals(
   insertInto(quote("Metrics"), quote("epochs")).toString(),
   "INSERT INTO \"Metrics\".\"epochs\" () VALUES ();");
}

代码示例来源:origin: stackoverflow.com

String sql ="select * from test where name = '한글왜안됨'";
Select select = (Select) CCJSqlParserUtil.parse(sql);
System.out.println(select.toString());

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

assertThat(select().all().from("foo").groupBy("c1", column("c2"), raw("c3")).toString())
  .isEqualTo("SELECT * FROM foo GROUP BY c1,c2,c3;");
assertThat(
      .groupBy("c1", column("c2"), raw("c3"))
      .orderBy(asc("c1"))
      .toString())
  .isEqualTo("SELECT * FROM foo GROUP BY c1,c2,c3 ORDER BY c1 ASC;");
assertThat(
      .where(eq("x", 42))
      .groupBy("c1", column("c2"), raw("c3"))
      .toString())
  .isEqualTo("SELECT * FROM foo WHERE x=42 GROUP BY c1,c2,c3;");
assertThat(
      .groupBy("c1", column("c2"), raw("c3"))
      .orderBy(asc("c1"))
      .toString())
  .isEqualTo("SELECT * FROM foo WHERE x=42 GROUP BY c1,c2,c3 ORDER BY c1 ASC;");
try {

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "unit")
public void should_handle_per_partition_limit_clause() {
 assertThat(select().all().from("foo").perPartitionLimit(2).toString())
   .isEqualTo("SELECT * FROM foo PER PARTITION LIMIT 2;");
 assertThat(select().all().from("foo").perPartitionLimit(bindMarker()).toString())
   .isEqualTo("SELECT * FROM foo PER PARTITION LIMIT ?;");
 assertThat(select().all().from("foo").perPartitionLimit(bindMarker("limit")).toString())
   .isEqualTo("SELECT * FROM foo PER PARTITION LIMIT :limit;");
 assertThat(select().all().from("foo").perPartitionLimit(2).limit(bindMarker()).toString())
   .isEqualTo("SELECT * FROM foo PER PARTITION LIMIT 2 LIMIT ?;");
 assertThat(
       .perPartitionLimit(2)
       .limit(3)
       .toString())
   .isEqualTo("SELECT * FROM foo WHERE a IN (2,4) PER PARTITION LIMIT 2 LIMIT 3;");
 assertThat(
       .perPartitionLimit(bindMarker())
       .limit(3)
       .toString())
   .isEqualTo("SELECT * FROM foo WHERE a=? PER PARTITION LIMIT ? LIMIT 3;");
 assertThat(
       .perPartitionLimit(2)
       .limit(3)
       .toString())
   .isEqualTo("SELECT * FROM foo WHERE a=? ORDER BY b DESC PER PARTITION LIMIT 2 LIMIT 3;");
 assertThat(

代码示例来源:origin: org.opennms.newts/newts-cassandra-search

@Inject
public CassandraCachePrimer(CassandraSession session) {
  m_session = checkNotNull(session);
  Select select = QueryBuilder.select(Constants.Schema.C_METRICS_CONTEXT,
      Constants.Schema.C_METRICS_RESOURCE,
      Constants.Schema.C_METRICS_NAME)
      .from(Constants.Schema.T_METRICS);
  m_selectAllMetricsStatement = session.prepare(select.toString());
  select = QueryBuilder.select(Constants.Schema.C_ATTRS_CONTEXT,
      Constants.Schema.C_ATTRS_RESOURCE,
      Constants.Schema.C_ATTRS_ATTR,
      Constants.Schema.C_ATTRS_VALUE)
      .from(Constants.Schema.T_ATTRS);
  m_selectAllAttributesStatement = session.prepare(select.toString());
}

代码示例来源:origin: OpenNMS/newts

@Inject
public CassandraCachePrimer(CassandraSession session) {
  m_session = checkNotNull(session);
  Select select = QueryBuilder.select(Constants.Schema.C_METRICS_CONTEXT,
      Constants.Schema.C_METRICS_RESOURCE,
      Constants.Schema.C_METRICS_NAME)
      .from(Constants.Schema.T_METRICS);
  m_selectAllMetricsStatement = session.prepare(select.toString());
  select = QueryBuilder.select(Constants.Schema.C_ATTRS_CONTEXT,
      Constants.Schema.C_ATTRS_RESOURCE,
      Constants.Schema.C_ATTRS_ATTR,
      Constants.Schema.C_ATTRS_VALUE)
      .from(Constants.Schema.T_ATTRS);
  m_selectAllAttributesStatement = session.prepare(select.toString());
}

代码示例来源:origin: com.datastax.dse/dse-java-driver-core

/** @test_category queries:builder */
@Test(groups = "unit")
public void should_handle_allow_filtering() {
 assertThat(select().all().from("foo").allowFiltering().toString())
   .isEqualTo("SELECT * FROM foo ALLOW FILTERING;");
 assertThat(select().all().from("foo").where(eq("x", 42)).allowFiltering().toString())
   .isEqualTo("SELECT * FROM foo WHERE x=42 ALLOW FILTERING;");
}

代码示例来源:origin: com.datastax.dse/dse-java-driver-core

@Test(groups = "unit")
public void should_handle_to_json() throws Exception {
 assertThat(select().toJson("id").as("id").toJson("age").as("age").from("users").toString())
   .isEqualTo("SELECT toJson(id) AS id,toJson(age) AS age FROM users;");
 assertThat(select().distinct().toJson("id").as("id").from("users").toString())
   .isEqualTo("SELECT DISTINCT toJson(id) AS id FROM users;");
 assertThat(
     select(alias(toJson("id"), "id"), alias(toJson("age"), "age")).from("users").toString())
   .isEqualTo("SELECT toJson(id) AS id,toJson(age) AS age FROM users;");
 assertThat(select(alias(toJson("id"), "id")).distinct().from("users").toString())
   .isEqualTo("SELECT DISTINCT toJson(id) AS id FROM users;");
}

代码示例来源:origin: OpenNMS/newts

@Inject
public CassandraSearcher(CassandraSession session, MetricRegistry registry, ContextConfigurations contextConfigurations) {
  m_session = checkNotNull(session, "session argument");
  m_searchTimer = registry.timer(name("search", "search"));
  m_contextConfigurations = checkNotNull(contextConfigurations, "contextConfigurations argument");
  Select select = QueryBuilder.select(Schema.C_TERMS_RESOURCE).from(Schema.T_TERMS);
  select.where(eq(Schema.C_TERMS_CONTEXT, bindMarker(Schema.C_TERMS_CONTEXT)))
     .and(  eq(Schema.C_TERMS_FIELD, bindMarker(Schema.C_TERMS_FIELD)))
     .and(  eq(Schema.C_TERMS_VALUE, bindMarker(Schema.C_TERMS_VALUE)));
  m_searchStatement = m_session.prepare(select.toString());
  select = QueryBuilder.select(Schema.C_ATTRS_ATTR, Schema.C_ATTRS_VALUE).from(Schema.T_ATTRS);
  select.where(eq(Schema.C_ATTRS_CONTEXT, bindMarker(Schema.C_ATTRS_CONTEXT)))
     .and(  eq(Schema.C_ATTRS_RESOURCE, bindMarker(Schema.C_ATTRS_RESOURCE)));
  m_selectAttributesStatement = m_session.prepare(select.toString());
  select = QueryBuilder.select(Schema.C_METRICS_NAME).from(Schema.T_METRICS);
  select.where(eq(Schema.C_METRICS_CONTEXT, bindMarker(Schema.C_METRICS_CONTEXT)))
     .and(  eq(Schema.C_METRICS_RESOURCE, bindMarker(Schema.C_METRICS_RESOURCE)));
  m_selectMetricNamesStatement = m_session.prepare(select.toString());
}

代码示例来源:origin: org.opennms.newts/newts-cassandra-search

@Inject
public CassandraSearcher(CassandraSession session, MetricRegistry registry, ContextConfigurations contextConfigurations) {
  m_session = checkNotNull(session, "session argument");
  m_searchTimer = registry.timer(name("search", "search"));
  m_contextConfigurations = checkNotNull(contextConfigurations, "contextConfigurations argument");
  Select select = QueryBuilder.select(Schema.C_TERMS_RESOURCE).from(Schema.T_TERMS);
  select.where(eq(Schema.C_TERMS_CONTEXT, bindMarker(Schema.C_TERMS_CONTEXT)))
     .and(  eq(Schema.C_TERMS_FIELD, bindMarker(Schema.C_TERMS_FIELD)))
     .and(  eq(Schema.C_TERMS_VALUE, bindMarker(Schema.C_TERMS_VALUE)));
  m_searchStatement = m_session.prepare(select.toString());
  select = QueryBuilder.select(Schema.C_ATTRS_ATTR, Schema.C_ATTRS_VALUE).from(Schema.T_ATTRS);
  select.where(eq(Schema.C_ATTRS_CONTEXT, bindMarker(Schema.C_ATTRS_CONTEXT)))
     .and(  eq(Schema.C_ATTRS_RESOURCE, bindMarker(Schema.C_ATTRS_RESOURCE)));
  m_selectAttributesStatement = m_session.prepare(select.toString());
  select = QueryBuilder.select(Schema.C_METRICS_NAME).from(Schema.T_METRICS);
  select.where(eq(Schema.C_METRICS_CONTEXT, bindMarker(Schema.C_METRICS_CONTEXT)))
     .and(  eq(Schema.C_METRICS_RESOURCE, bindMarker(Schema.C_METRICS_RESOURCE)));
  m_selectMetricNamesStatement = m_session.prepare(select.toString());
}

代码示例来源:origin: org.apache.beam/beam-sdks-java-io-cassandra

@Override
public List<BoundedSource<T>> split(CassandraIO.Read<T> spec, long desiredBundleSizeBytes) {
 try (Cluster cluster =
   getCluster(
     spec.hosts(),
     spec.port(),
     spec.username(),
     spec.password(),
     spec.localDc(),
     spec.consistencyLevel())) {
  if (isMurmur3Partitioner(cluster)) {
   LOG.info("Murmur3Partitioner detected, splitting");
   return split(spec, desiredBundleSizeBytes, getEstimatedSizeBytes(spec), cluster);
  } else {
   LOG.warn(
     "Only Murmur3Partitioner is supported for splitting, using an unique source for "
       + "the read");
   String splitQuery = QueryBuilder.select().from(spec.keyspace(), spec.table()).toString();
   return Collections.singletonList(
     new CassandraIO.CassandraSource<>(spec, Collections.singletonList(splitQuery)));
  }
 }
}

代码示例来源:origin: com.datastax.dse/dse-java-driver-core

@Test(groups = "unit")
public void should_handle_select_json() throws Exception {
 assertThat(select().json().from("users").toString()).isEqualTo("SELECT JSON * FROM users;");
 assertThat(select("id", "age").json().from("users").toString())
   .isEqualTo("SELECT JSON id,age FROM users;");
 assertThat(
     select()
       .json()
       .column("id")
       .writeTime("age")
       .ttl("state")
       .as("ttl")
       .from("users")
       .toString())
   .isEqualTo("SELECT JSON id,writetime(age),ttl(state) AS ttl FROM users;");
 assertThat(select().distinct().json().column("id").from("users").toString())
   .isEqualTo(
     "SELECT JSON DISTINCT id FROM users;"); // note that the correct syntax is JSON DISTINCT
}

代码示例来源:origin: OpenNMS/newts

@Inject
public CassandraSampleRepository(CassandraSession session, @Named("samples.cassandra.time-to-live") int ttl, MetricRegistry registry, SampleProcessorService processorService, ContextConfigurations contextConfigurations) {
  m_session = checkNotNull(session, "session argument");
  checkArgument(ttl >= 0, "Negative Cassandra column TTL");
  m_ttl = ttl;
  checkNotNull(registry, "metric registry argument");
  m_processorService = processorService;
  m_contextConfigurations = checkNotNull(contextConfigurations, "contextConfigurations argument");
  Select select = QueryBuilder.select().from(SchemaConstants.T_SAMPLES);
  select.where(eq(SchemaConstants.F_CONTEXT, bindMarker(SchemaConstants.F_CONTEXT)));
  select.where(eq(SchemaConstants.F_PARTITION, bindMarker(SchemaConstants.F_PARTITION)));
  select.where(eq(SchemaConstants.F_RESOURCE, bindMarker(SchemaConstants.F_RESOURCE)));
  select.where(gte(SchemaConstants.F_COLLECTED, bindMarker("start")));
  select.where(lte(SchemaConstants.F_COLLECTED, bindMarker("end")));
  m_selectStatement = m_session.prepare(select.toString());
  Delete delete = QueryBuilder.delete().from(SchemaConstants.T_SAMPLES);
  delete.where(eq(SchemaConstants.F_CONTEXT, bindMarker(SchemaConstants.F_CONTEXT)));
  delete.where(eq(SchemaConstants.F_PARTITION, bindMarker(SchemaConstants.F_PARTITION)));
  delete.where(eq(SchemaConstants.F_RESOURCE, bindMarker(SchemaConstants.F_RESOURCE)));
  m_deleteStatement = m_session.prepare(delete.toString());
  m_sampleSelectTimer = registry.timer(metricName("sample-select-timer"));
  m_measurementSelectTimer = registry.timer(metricName("measurement-select-timer"));
  m_insertTimer = registry.timer(metricName("insert-timer"));
  m_samplesInserted = registry.meter(metricName("samples-inserted"));
  m_samplesSelected = registry.meter(metricName("samples-selected"));
}

代码示例来源:origin: com.datastax.dse/dse-java-driver-core

@Test(groups = "unit")
public void quotingTest() {
 assertEquals(select().from("Metrics", "epochs").toString(), "SELECT * FROM Metrics.epochs;");
 assertEquals(
   select().from("Metrics", quote("epochs")).toString(), "SELECT * FROM Metrics.\"epochs\";");
 assertEquals(
   select().from(quote("Metrics"), "epochs").toString(), "SELECT * FROM \"Metrics\".epochs;");
 assertEquals(
   select().from(quote("Metrics"), quote("epochs")).toString(),
   "SELECT * FROM \"Metrics\".\"epochs\";");
 assertEquals(
   insertInto("Metrics", "epochs").toString(), "INSERT INTO Metrics.epochs () VALUES ();");
 assertEquals(
   insertInto("Metrics", quote("epochs")).toString(),
   "INSERT INTO Metrics.\"epochs\" () VALUES ();");
 assertEquals(
   insertInto(quote("Metrics"), "epochs").toString(),
   "INSERT INTO \"Metrics\".epochs () VALUES ();");
 assertEquals(
   insertInto(quote("Metrics"), quote("epochs")).toString(),
   "INSERT INTO \"Metrics\".\"epochs\" () VALUES ();");
}

代码示例来源:origin: com.yugabyte/cassandra-driver-mapping

@Override
  String makePreparedQueryString(TableMetadata table, EntityMapper<?> mapper, MappingManager manager, Set<AliasedMappedProperty> columns, Collection<Mapper.Option> options) {
    Select.Selection selection = select();
    for (AliasedMappedProperty col : mapper.allColumns) {
      Select.SelectionOrAlias column = col.mappedProperty.isComputed()
          ? selection.raw(col.mappedProperty.getMappedName())
          : selection.column(col.mappedProperty.getMappedName());
      if (col.alias == null) {
        selection = column;
      } else {
        selection = column.as(col.alias);
      }
    }
    Select select;
    if (table == null) {
      select = selection.from(mapper.keyspace, mapper.table);
    } else {
      select = selection.from(table);
    }
    Select.Where where = select.where();
    for (int i = 0; i < mapper.primaryKeySize(); i++)
      where.and(eq(mapper.getPrimaryKeyColumn(i).mappedProperty.getMappedName(), bindMarker()));
    for (Mapper.Option option : options) {
      option.validate(QueryType.GET, manager);
      option.modifyQueryString(select);
    }
    return select.toString();
  }
},

相关文章