/** * Adds an ORDER BY clause to the {@code SELECT} statement this {@code WHERE} clause if part of. * * @param orderings the orderings to add. * @return the {@code SELECT} statement this {@code WHERE} clause is part of. * @throws IllegalStateException if an {@code ORDER BY} clause has already been provided. */ public Select orderBy(Ordering... orderings) { return statement.orderBy(orderings); }
/** * Adds an ORDER BY clause to the SELECT statement this WHERE clause if * part of. * * @param orderings the orderings to add. * @return the select statement this Where clause if part of. * @throws IllegalStateException if an ORDER BY clause has already been * provided. */ public Select orderBy(Ordering... orderings) { return statement.orderBy(orderings); }
/** * Adds an ORDER BY clause to the SELECT statement this WHERE clause if * part of. * * @param orderings the orderings to add. * @return the select statement this Where clause if part of. * * @throws IllegalStateException if an ORDER BY clause has already been * provided. */ public Select orderBy(Ordering... orderings) { return statement.orderBy(orderings); }
/** * Adds an ORDER BY clause to the SELECT statement this WHERE clause if * part of. * * @param orderings the orderings to add. * @return the select statement this Where clause if part of. * @throws IllegalStateException if an ORDER BY clause has already been * provided. */ public Select orderBy(Ordering... orderings) { return statement.orderBy(orderings); }
/** * Adds an ORDER BY clause to the SELECT statement this WHERE clause if * part of. * * @param orderings the orderings to add. * @return the select statement this Where clause if part of. * @throws IllegalStateException if an ORDER BY clause has already been * provided. */ public Select orderBy(Ordering... orderings) { return statement.orderBy(orderings); }
.from("foo") .groupBy("c1", column("c2"), raw("c3")) .orderBy(asc("c1")) .toString()) .isEqualTo("SELECT * FROM foo GROUP BY c1,c2,c3 ORDER BY c1 ASC;"); .where(eq("x", 42)) .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;");
@Override public SelectBuilder<T> desc(String name) { select.orderBy(QueryBuilder.desc(classBean.toColumn(name))); return this; }
@Override public SelectBuilder<T> asc(String name) { select.orderBy(QueryBuilder.asc(classBean.toColumn(name))); return this; }
public Optional<DateTime> getTimeOfOldestIntervalTrafficDataMessage( MessageSource messageSource, IntegrationPeriod integrationPeriod, TrafficDataType trafficDataType ) { Select select = QueryBuilder.select( "message_time" ).from( "messages", "data_message" ); select.where( QueryBuilder.eq( "message_source_id", messageSource.getId().getId() ) ) .and( QueryBuilder.eq( "traffic_data_type", trafficDataType.name() ) ) .and( QueryBuilder.eq( "integration_period", integrationPeriod.name() ) ); select.orderBy( QueryBuilder.asc( "message_time" ) ); select.limit( 1 ); Date date = m_cassandraOperations.queryForObject( select, Date.class ); if( date != null ) { Optional<DateTime> result = Optional.of( new DateTime( date ) ); logger.debug( "oldest interval: {} ({}/{}/{})", result, messageSource.getName(), trafficDataType, integrationPeriod ); return result; } else { return Optional.absent(); } }
private Select prepare(Scan scan) { Select select = getSelect(scan); createStatement(select.where(), scan); List<Ordering> orderings = getOrderings(scan.getOrderings()); if (!orderings.isEmpty()) { select.orderBy(orderings.toArray(new Ordering[orderings.size()])); } if (scan.getLimit() > 0) { select.limit(scan.getLimit()); } return select; }
.where(eq("a", 1)) .groupBy("a", "b", "c") .orderBy(desc("b"), desc("c")))) .containsExactly(row(1, 4, 24, 2L, 24), row(1, 2, 12, 1L, 12), row(1, 2, 6, 1L, 6)); .where(eq("a", 1)) .groupBy("a", "b", "c") .orderBy(desc("b"), desc("c")) .perPartitionLimit(1))) .containsExactly(row(1, 4, 24, 2L, 24)); .where(eq("a", 1)) .groupBy("a", "b", "c") .orderBy(desc("b"), desc("c")) .limit(2))) .containsExactly(row(1, 4, 24, 2L, 24), row(1, 2, 12, 1L, 12)); .where(in("a", 1, 2, 4)) .groupBy("a", "b") .orderBy(desc("b"), desc("c")) .setFetchSize(Integer.MAX_VALUE))) .containsExactly( .where(in("a", 1, 2, 4)) .groupBy("a", "b") .orderBy(desc("b"), desc("c")) .limit(3) .setFetchSize(Integer.MAX_VALUE)))
private static Select createSelectAndOrder(List<Selector> selectors, CqlIdentifier from, Filter filter, Sort sort) { Select select; if (selectors.isEmpty()) { select = QueryBuilder.select().all().from(from.toCql()); } else { Selection selection = QueryBuilder.select(); selectors.forEach(selector -> selector.getAlias().map(CqlIdentifier::toCql).ifPresent(getSelection(selection, selector)::as)); select = selection.from(from.toCql()); } for (CriteriaDefinition criteriaDefinition : filter) { select.where(toClause(criteriaDefinition)); } if (sort.isSorted()) { List<Ordering> orderings = new ArrayList<>(); for (Order order : sort) { if (order.isAscending()) { orderings.add(QueryBuilder.asc(order.getProperty())); } else { orderings.add(QueryBuilder.desc(order.getProperty())); } } if (!orderings.isEmpty()) { select.orderBy(orderings.toArray(new Ordering[orderings.size()])); } } return select; }
sel.orderBy(orderings);
Factory(Session session, TimestampCodec timestampCodec) { this.session = session; this.timestampCodec = timestampCodec; this.preparedStatement = session.prepare( QueryBuilder.select("ts", "trace_id") .from(Tables.SERVICE_SPAN_NAME_INDEX) .where( QueryBuilder.eq( "service_span_name", QueryBuilder.bindMarker("service_span_name"))) .and(QueryBuilder.gte("ts", QueryBuilder.bindMarker("start_ts"))) .and(QueryBuilder.lte("ts", QueryBuilder.bindMarker("end_ts"))) .limit(QueryBuilder.bindMarker("limit_")) .orderBy(QueryBuilder.desc("ts"))); }
Factory(Session session, TimestampCodec timestampCodec, Set<Integer> buckets) { this.session = session; this.timestampCodec = timestampCodec; this.preparedStatement = session.prepare( QueryBuilder.select("ts", "trace_id") .from(Tables.ANNOTATIONS_INDEX) .where(QueryBuilder.eq("annotation", QueryBuilder.bindMarker("annotation"))) .and(QueryBuilder.in("bucket", buckets)) .and(QueryBuilder.gte("ts", QueryBuilder.bindMarker("start_ts"))) .and(QueryBuilder.lte("ts", QueryBuilder.bindMarker("end_ts"))) .limit(QueryBuilder.bindMarker("limit_")) .orderBy(QueryBuilder.desc("ts"))); }
Factory(Session session, TimestampCodec timestampCodec, Set<Integer> buckets) { this.session = session; this.timestampCodec = timestampCodec; this.preparedStatement = session.prepare( QueryBuilder.select("ts", "trace_id") .from(Tables.SERVICE_NAME_INDEX) .where(QueryBuilder.in("service_name", QueryBuilder.bindMarker("service_names"))) .and(QueryBuilder.in("bucket", buckets)) .and(QueryBuilder.gte("ts", QueryBuilder.bindMarker("start_ts"))) .and(QueryBuilder.lte("ts", QueryBuilder.bindMarker("end_ts"))) .limit(QueryBuilder.bindMarker("limit_")) .orderBy(QueryBuilder.desc("ts"))); }
Factory(Session session, TimestampCodec timestampCodec, Set<Integer> buckets) { this.session = session; this.timestampCodec = timestampCodec; this.preparedStatement = session.prepare( QueryBuilder.select("ts", "trace_id") .from(Tables.SERVICE_NAME_INDEX) .where(QueryBuilder.eq("service_name", QueryBuilder.bindMarker("service_name"))) .and(QueryBuilder.in("bucket", buckets)) .and(QueryBuilder.gte("ts", QueryBuilder.bindMarker("start_ts"))) .and(QueryBuilder.lte("ts", QueryBuilder.bindMarker("end_ts"))) .limit(QueryBuilder.bindMarker("limit_")) .orderBy(QueryBuilder.desc("ts"))); }
.from("foo") .groupBy("c1", column("c2"), raw("c3")) .orderBy(asc("c1")) .toString()) .isEqualTo("SELECT * FROM foo GROUP BY c1,c2,c3 ORDER BY c1 ASC;"); .where(eq("x", 42)) .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;");