private Result<? extends Record> fetchValues(DSLContext ctx, TableReference tableRef, Select<? extends Record> subQuery) { return ctx.select(A_ROW_NAME, A_COL_NAME, A_TIMESTAMP, A_VALUE) .from(atlasTable(tableRef).as(ATLAS_TABLE)) .join(subQuery.asTable(TEMP_TABLE_2)) .on(A_ROW_NAME.eq(T2_ROW_NAME) .and(A_COL_NAME.eq(T2_COL_NAME)) .and(A_TIMESTAMP.eq(T2_MAX_TIMESTAMP))) .fetch(); }
/** * A synonym for {@link Select#asTable()}, which might look a bit more fluent * like this, to some users. * * @see Select#asTable() */ @Support public static <R extends Record> Table<R> table(Select<R> select) { return select.asTable(); }
@Override public final Table<R> asTable(String alias, String... fieldAliases) { return getDelegate().asTable(alias, fieldAliases); }
@Override public final Table<R> asTable(String alias, BiFunction<? super Field<?>, ? super Integer, ? extends String> aliasFunction) { return getDelegate().asTable(alias, aliasFunction); }
@Override public final Table<R> asTable() { return getDelegate().asTable(); }
@Override public final Table<R> asTable(String alias) { return getDelegate().asTable(alias); }
@Override public final Table<R> asTable(String alias, Function<? super Field<?>, ? extends String> aliasFunction) { return getDelegate().asTable(alias, aliasFunction); }
@Override public final Table<R> asTable() { return getDelegate().asTable(); }
@Override public final Table<R> asTable(String alias) { return getDelegate().asTable(alias); }
@Override public final Table<R> asTable(String alias, String... fieldAliases) { return getDelegate().asTable(alias, fieldAliases); }
/** * A synonym for {@link Select#asTable()}, which might look a bit more fluent * like this, to some users. * * @see Select#asTable() */ @Support @Transition( name = "TABLE", args = "Select", to = "UnnestedTable" ) public static <R extends Record> Table<R> table(Select<R> select) { return select.asTable(); }
private final QueryPart delegate(Configuration configuration) { switch (configuration.family()) { default: return select(count).from(query.asTable("q")); } }
public Set<String> getTagValuesForKey(String tagKey, Map<String, String> restrictions, User user) { if (restrictions.isEmpty()) { return getTagValuesForKey(tagKey, user); } Set<String> keys = new HashSet<>(); keys.addAll(restrictions.keySet()); keys.add(tagKey); Map<String, Name> tagKeyToColumn = tagKeyToColumn(keys); Name tagKeyColumn = tagKeyToColumn.get(tagKey); List<Condition> conditions = restrictions.entrySet().stream().map(e -> { return DSL.field(DATA_POINT_TAGS_PIVOT_ALIAS.append(tagKeyToColumn.get(e.getKey()))).eq(e.getValue()); }).collect(Collectors.toCollection(ArrayList::new)); Table<Record> from = createTagPivotSql(tagKeyToColumn).asTable().as(DATA_POINT_TAGS_PIVOT_ALIAS); if (!user.hasAdminPermission()) { from = joinPointPermissions(from, PIVOT_ALIAS_DATA_POINT_ID, user); } Select<Record1<String>> result = this.create .selectDistinct(DSL.field(DATA_POINT_TAGS_PIVOT_ALIAS.append(tagKeyColumn), String.class)) .from(from) .where(DSL.and(conditions)); try (Stream<Record1<String>> stream = result.stream()) { return stream.map(r -> r.value1()).collect(Collectors.toSet()); } }
/** * Gets data points for a set of tags that a user has access to (i.e. readPermission, setPermission or the datasource editPermission). * * @param restrictions * @param user * @param callback * @param sort (may be null) * @param limit (may be null) * @param offset (may be null) */ public void dataPointsForTags(Map<String, String> restrictions, User user, MappedRowCallback<DataPointVO> callback, List<SortField<Object>> sort, Integer limit, Integer offset) { if (restrictions.isEmpty()) { throw new IllegalArgumentException("restrictions should not be empty"); } Map<String, Name> tagKeyToColumn = DataPointTagsDao.getInstance().tagKeyToColumn(restrictions.keySet()); List<Condition> conditions = restrictions.entrySet().stream().map(e -> { return DSL.field(DATA_POINT_TAGS_PIVOT_ALIAS.append(tagKeyToColumn.get(e.getKey()))).eq(e.getValue()); }).collect(Collectors.toCollection(ArrayList::new)); if (!user.hasAdminPermission()) { conditions.add(this.userHasPermission(user)); } Table<Record> pivotTable = DataPointTagsDao.getInstance().createTagPivotSql(tagKeyToColumn).asTable().as(DATA_POINT_TAGS_PIVOT_ALIAS); SelectOnConditionStep<Record> select = this.create.select(this.fields).from(this.joinedTable).leftJoin(pivotTable) .on(DataPointTagsDao.PIVOT_ALIAS_DATA_POINT_ID.eq(ID)); this.customizedQuery(select, DSL.and(conditions), sort, limit, offset, callback); }
private final QueryPart delegate(Configuration configuration) { switch (configuration.dialect().family()) { /* [pro] xx xx xxxxxxx xxxx xxxxxxxx xxxxxx xxxx xxxxxxx xxxxxx xxxx xxxxxxx xx xxxxxxx xx xxxxx xxxxx x xxxxxxx xxxxxx xxxx xxxxxxxx xxxx xxxxxxxxxx xxxx xxxxxxx x xxxxxxxxxxxxxx xxxxxx x xxxxxxxxxxxxxxxxxx xxxxxxxx xxxxx x xxx xxxxxxxxxxxxxxxxxxxxxx xxx xxxx x x xx x x xxxxxxxxxxxxx xxxx xxxxxxxx x xxx x xx x xxx xxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxx x xx [/pro] */ default: return select(count).from(query.asTable("q")); } }
@Override public <R extends Record> SelectJoinStep<R> joinTables(SelectJoinStep<R> select, ConditionSortLimit conditions) { if (conditions instanceof ConditionSortLimitWithTagKeys) { Map<String, Name> tagKeyToColumn = ((ConditionSortLimitWithTagKeys) conditions).getTagKeyToColumn(); if (!tagKeyToColumn.isEmpty()) { Table<Record> pivotTable = DataPointTagsDao.getInstance().createTagPivotSql(tagKeyToColumn).asTable().as(DATA_POINT_TAGS_PIVOT_ALIAS); return select.leftJoin(pivotTable) .on(DataPointTagsDao.PIVOT_ALIAS_DATA_POINT_ID.eq(ID)); } } return select; }
public Set<String> getTagValuesForKey(String tagKey, ASTNode restrictions, User user) { RQLToConditionWithTagKeys visitor = new RQLToConditionWithTagKeys(); Name tagKeyColumn = visitor.columnNameForTagKey(tagKey); List<Condition> conditionList = new ArrayList<>(); ConditionSortLimitWithTagKeys conditions = visitor.visit(restrictions); if (conditions.getCondition() != null) { conditionList.add(conditions.getCondition()); } Map<String, Name> tagKeyToColumn = conditions.getTagKeyToColumn(); Table<Record> from = createTagPivotSql(tagKeyToColumn).asTable().as(DATA_POINT_TAGS_PIVOT_ALIAS); if (!user.hasAdminPermission()) { from = joinPointPermissions(from, PIVOT_ALIAS_DATA_POINT_ID, user); } SelectJoinStep<Record1<String>> query = this.create .selectDistinct(DSL.field(DATA_POINT_TAGS_PIVOT_ALIAS.append(tagKeyColumn), String.class)) .from(from); Select<Record1<String>> result = query; if (!conditionList.isEmpty()) { result = query.where(DSL.and(conditionList)); } try (Stream<Record1<String>> stream = result.stream()) { return stream.map(r -> r.value1()).collect(Collectors.toSet()); } }
.select(selectFields) .from(recordTable) .join(select.asTable().as(distinctAlias)) .on(recordTypeIdField.eq(DSL.field(DSL.name(distinctAlias, recordTypeIdField.getName()), uuidType))) .and(recordIdField.eq(DSL.field(DSL.name(distinctAlias, recordIdField.getName()), uuidType)));
private final Table<Record> table(Configuration configuration) { if (table == null) { Select<Record> select = null; for (Object element : array) { // [#1081] Be sure to get the correct cast type also for null Field<?> val = DSL.val(element, field.fields[0].getDataType()); Select<Record> subselect = using(configuration).select(val.as("COLUMN_VALUE")).select(); if (select == null) { select = subselect; } else { select = select.unionAll(subselect); } } // Empty arrays should result in empty tables if (select == null) { select = using(configuration).select(one().as("COLUMN_VALUE")).select().where(falseCondition()); } table = select.asTable(alias); } return table; } }
select().from(right.asTable(table, names)) .where(condition);