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); }
return distinct ? avgDistinct(arg) : avg(arg); case MAX: return distinct ? maxDistinct(arg) : max(arg); case MIN: return distinct ? minDistinct(arg) : min(arg);
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> 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> 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); }
@Override @Deprecated public final Field<T> max() { return DSL.max(this); }
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); }
@Override @Deprecated public final Field<T> max() { return DSL.max(this); }
@Override @Deprecated public final WindowPartitionByStep<T> maxOver() { return DSL.max(this).over(); }
@Override @Deprecated public final WindowPartitionByStep<T> maxOver() { return DSL.max(this).over(); }
/** * This method does not filter the tags based on the data point permissions. It should only be used * when joining onto the data points table (the filtering happens there post-join). * * @param tagKeyToColumn * @return */ Select<Record> createTagPivotSql(Map<String, Name> tagKeyToColumn) { List<Field<?>> fields = new ArrayList<>(tagKeyToColumn.size() + 1); fields.add(DATA_POINT_ID); for (Entry<String, Name> entry : tagKeyToColumn.entrySet()) { fields.add(DSL.max(DSL.when(TAG_KEY.eq(entry.getKey()), TAG_VALUE)).as(entry.getValue())); } return DSL.select(fields).from(DATA_POINT_TAGS).groupBy(DATA_POINT_ID); }
@Override public void accept(Context<?> c) { c.visit(DSL.max(DSL.when(condition, one()).otherwise(zero()))); toSQLOverClause(c); } });
@Override public Map<String, Integer> findCollections() { Collection<CollectionSchema> collections = meta.getCollectionSchemes(); Map<String, Integer> result = Maps.newHashMapWithExpectedSize(collections.size()); for (CollectionSchema colSchema : collections) { int firstFree = Routines.firstFreeDocId(jooqConf, colSchema); result.put(colSchema.getCollection(), firstFree); Integer lastUsed = (Integer) getDsl().select(DSL.max(DSL.field("did"))) .from(DSL.table(DSL.name(colSchema.getName(), "root"))) .fetchOne().value1(); LOGGER.debug("Collection {} has {} as last used id", colSchema.getName(), lastUsed); if (lastUsed == null) { lastUsed = 0; } if (lastUsed >= firstFree) { LOGGER.warn( "Collection {}.root: last used = {}. First free = {}", new Object[]{ colSchema.getName(), lastUsed, firstFree } ); } } return result; }
@WithTimer public int getDepth(UUID parentInstanceId) { return txResult(tx -> tx.withRecursive("ancestors").as( select(PROCESS_QUEUE.INSTANCE_ID, PROCESS_QUEUE.PARENT_INSTANCE_ID, field("1", Integer.class).as("depth")) .from(PROCESS_QUEUE) .where(PROCESS_QUEUE.INSTANCE_ID.eq(parentInstanceId)) .unionAll( select(PROCESS_QUEUE.INSTANCE_ID, PROCESS_QUEUE.PARENT_INSTANCE_ID, field("1 + ancestors.depth", Integer.class).as("depth")) .from(PROCESS_QUEUE) .join(name("ancestors")) .on(PROCESS_QUEUE.INSTANCE_ID.eq( field(name("ancestors", "PARENT_INSTANCE_ID"), UUID.class))))) .select(max(field(name("ancestors", "depth"), Integer.class))) .from(name("ancestors")) .fetchOne(Record1::value1)); } }
pn.NSPNAME, pt.RELNAME, max(i.INHSEQNO).over().partitionBy(i.INHRELID).as("m")