private Select<? extends Record> getAllTimestampsQueryAllColumns(DSLContext ctx, TableReference tableRef, Select<Record1<byte[]>> subQuery, long timestamp) { return ctx.select(A_ROW_NAME, A_COL_NAME, A_TIMESTAMP) .from(atlasTable(tableRef).as(ATLAS_TABLE)) .where(A_ROW_NAME.in(subQuery) .and(A_TIMESTAMP.lessThan(timestamp))); }
@Override public Multimap<Cell, Long> getAllTimestamps(final TableReference tableRef, final Set<Cell> cells, final long timestamp) throws InsufficientConsistencyException { if (cells.isEmpty()) { return ImmutableMultimap.of(); } Multimap<Cell, Long> toReturn = ArrayListMultimap.create(); for (List<Cell> partition : Iterables.partition(cells, batchSizeForReads)) { toReturn.putAll(run(ctx -> { Result<? extends Record> records = ctx .select(A_ROW_NAME, A_COL_NAME, A_TIMESTAMP) .from(atlasTable(tableRef).as(ATLAS_TABLE)) .join(values(ctx, toRows(Sets.newHashSet(partition)), TEMP_TABLE_1, ROW_NAME, COL_NAME)) .on(A_ROW_NAME.eq(T1_ROW_NAME) .and(A_COL_NAME.eq(T1_COL_NAME))) .where(A_TIMESTAMP.lessThan(timestamp)) .fetch(); Multimap<Cell, Long> results = ArrayListMultimap.create(records.size() / 4, 4); for (Record record : records) { results.put( Cell.create(record.getValue(A_ROW_NAME), record.getValue(A_COL_NAME)), record.getValue(A_TIMESTAMP)); } return results; })); } return toReturn; }
private Select<? extends Record> getAllTimestampsQuerySomeColumns(DSLContext ctx, TableReference tableRef, Select<Record1<byte[]>> subQuery, Collection<byte[]> cols, long timestamp) { return ctx.select(A_ROW_NAME, A_COL_NAME, A_TIMESTAMP) .from(atlasTable(tableRef).as(ATLAS_TABLE)) .where(A_ROW_NAME.in(subQuery) .and(A_COL_NAME.in(cols))) .and(A_TIMESTAMP.lessThan(timestamp)); }
private Select<? extends Record> getLatestTimestampQueryAllColumns(DSLContext ctx, TableReference tableRef, Collection<byte[]> rows, long timestamp) { return ctx.select(A_ROW_NAME, A_COL_NAME, DSL.max(A_TIMESTAMP).as(MAX_TIMESTAMP)) .from(atlasTable(tableRef).as(ATLAS_TABLE)) .where(A_ROW_NAME.in(rows) .and(A_TIMESTAMP.lessThan(timestamp))) .groupBy(A_ROW_NAME, A_COL_NAME); }
private Select<? extends Record> getLatestTimestampQueryAllColumnsSubQuery(DSLContext ctx, TableReference tableRef, Select<Record1<byte[]>> subQuery, long timestamp) { return ctx.select(A_ROW_NAME, A_COL_NAME, DSL.max(A_TIMESTAMP).as(MAX_TIMESTAMP)) .from(atlasTable(tableRef).as(ATLAS_TABLE)) .where(A_ROW_NAME.in(subQuery) .and(A_TIMESTAMP.lessThan(timestamp))) .groupBy(A_ROW_NAME, A_COL_NAME); }
private SelectOffsetStep<Record1<byte[]>> getRangeQuery(DSLContext ctx, TableReference tableRef, RangeRequest rangeRequest, long timestamp, int maxRows) { boolean reverse = rangeRequest.isReverse(); byte[] start = rangeRequest.getStartInclusive(); byte[] end = rangeRequest.getEndExclusive(); Condition cond = R_TIMESTAMP.lessThan(timestamp); if (start.length > 0) { cond = cond.and(reverse ? R_ROW_NAME.lessOrEqual(start) : R_ROW_NAME.greaterOrEqual(start)); } if (end.length > 0) { cond = cond.and(reverse ? R_ROW_NAME.greaterThan(end) : R_ROW_NAME.lessThan(end)); } return ctx.selectDistinct(R_ROW_NAME) .from(atlasTable(tableRef).as(RANGE_TABLE)) .where(cond) .orderBy(reverse ? R_ROW_NAME.desc() : R_ROW_NAME.asc()) .limit(maxRows); }
private Select<? extends Record> getLatestTimestampQuerySomeColumns(DSLContext ctx, TableReference tableRef, Collection<byte[]> rows, Collection<byte[]> cols, long timestamp) { return ctx.select(A_ROW_NAME, A_COL_NAME, DSL.max(A_TIMESTAMP).as(MAX_TIMESTAMP)) .from(atlasTable(tableRef).as(ATLAS_TABLE)) .where(A_ROW_NAME.in(rows) .and(A_COL_NAME.in(cols))) .and(A_TIMESTAMP.lessThan(timestamp)) .groupBy(A_ROW_NAME, A_COL_NAME); }
private Select<? extends Record> getLatestTimestampQuerySomeColumnsSubQuery(DSLContext ctx, TableReference tableRef, Select<Record1<byte[]>> subQuery, Collection<byte[]> cols, long timestamp) { return ctx.select(A_ROW_NAME, A_COL_NAME, DSL.max(A_TIMESTAMP).as(MAX_TIMESTAMP)) .from(atlasTable(tableRef).as(ATLAS_TABLE)) .where(A_ROW_NAME.in(subQuery) .and(A_COL_NAME.in(cols))) .and(A_TIMESTAMP.lessThan(timestamp)) .groupBy(A_ROW_NAME, A_COL_NAME); }
private Select<? extends Record> getLatestTimestampQueryManyTimestamps(DSLContext ctx, TableReference tableRef, RowN[] rows) { return ctx.select(A_ROW_NAME, A_COL_NAME, DSL.max(A_TIMESTAMP).as(MAX_TIMESTAMP)) .from(atlasTable(tableRef).as(ATLAS_TABLE)) .join(values(ctx, rows, TEMP_TABLE_1, ROW_NAME, COL_NAME, TIMESTAMP)) .on(A_ROW_NAME.eq(T1_ROW_NAME) .and(A_COL_NAME.eq(T1_COL_NAME))) .where(A_TIMESTAMP.lessThan(T1_TIMESTAMP)) .groupBy(A_ROW_NAME, A_COL_NAME); }
private Condition getCompareCondition(Object value, BiPredicate<?, ?> biPredicate, Field<Object> field) { String predicateString = biPredicate.toString(); switch (predicateString) { case ("eq"): return field.eq(value); case ("neq"): return field.notEqual(value); case ("gt"): return field.greaterThan(value); case ("gte"): return field.greaterOrEqual(value); case ("lt"): return field.lessThan(value); case ("lte"): return field.lessOrEqual(value); case ("inside"): List items = (List) value; Object firstItem = items.get(0); Object secondItem = items.get(1); return field.between(firstItem, secondItem); default: throw new IllegalArgumentException("predicate not supported in has step: " + biPredicate.toString()); } }
return field.greaterOrEqual(convertToSqlDate(value.toString())); case ("lt"): return field.lessThan(convertToSqlDate(value.toString())); case ("lte"): return field.lessOrEqual(convertToSqlDate(value.toString()));
@SuppressWarnings("unchecked") @Override final Field<Integer> getFunction0(Configuration configuration) { switch (configuration.dialect()) { case SQLITE: return DSL .when(((Field<Integer>) argument).greaterThan(zero()), one()) .when(((Field<Integer>) argument).lessThan(zero()), one().neg()) .otherwise(zero()); default: return function("sign", getDataType(), argument); } } }
@SuppressWarnings("unchecked") @Override final Field<Integer> getFunction0(Configuration configuration) { switch (configuration.dialect()) { /* [pro] xx xxxx xxxxxxx xxxxxx xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxx xxxxxxxxxx xx [/pro] */ case SQLITE: return DSL.decode() .when(((Field<Integer>) argument).greaterThan(zero()), one()) .when(((Field<Integer>) argument).lessThan(zero()), one().neg()) .otherwise(zero()); default: return function("sign", getDataType(), argument); } } }
@Override public Condition visit(IsLessQueryCriteria criteria, Boolean inArray) { String[] keys = translateArrayRef(criteria); Field field = DSL.field(databaseInterface.arraySerializer().getFieldName(keys)); Param<?> value; Condition typeCondition = null; if (!isInArrayValue(criteria.getAttributeReference(), inArray)) { value = translateValueToSQL(criteria.getValue()); } else { value = translateValueToArraySerialization(criteria.getValue()); typeCondition = databaseInterface.arraySerializer().typeof( field.getName(), getJsonType(criteria.getValue().getType()) ); } Condition criteriaCondition = field.lessThan(value); if (typeCondition != null) { criteriaCondition = typeCondition.and(criteriaCondition); } return addArrayCondition(criteria, criteriaCondition, keys, inArray); }
public List<ProcessEntry> poll(PollEntry entry, Field<Timestamp> maxAge, int maxEntries) { ProcessQueue q = PROCESS_QUEUE.as("q"); return txResult(tx -> tx.select(q.INSTANCE_ID, q.CREATED_AT, q.PROJECT_ID, q.INITIATOR_ID) .from(q) .where(q.PROCESS_KIND.in(Utils.toString(HANDLED_PROCESS_KINDS)) .and(q.CURRENT_STATUS.eq(entry.status.toString())) .and(q.CREATED_AT.greaterOrEqual(maxAge)) .and(PgUtils.contains(q.HANDLERS, new String[]{entry.flow})) .and(noSuccessfulHandlers(q.INSTANCE_ID, entry.handlerKind)) .and(count(tx, q.INSTANCE_ID, entry.handlerKind).lessThan(entry.maxTries)) .and(noRunningHandlers(q.INSTANCE_ID))) .limit(maxEntries) .fetch(WatchdogDao::toEntry)); }