Class FindInStatement<IN,T extends tech.ydb.yoj.repository.db.Entity<T>,RESULT>
java.lang.Object
tech.ydb.yoj.repository.ydb.statement.YqlStatement<PARAMS,ENTITY,RESULT>
tech.ydb.yoj.repository.ydb.statement.MultipleVarsYqlStatement<IN,T,RESULT>
tech.ydb.yoj.repository.ydb.statement.FindInStatement<IN,T,RESULT>
- All Implemented Interfaces:
Statement<IN,RESULT>
public final class FindInStatement<IN,T extends tech.ydb.yoj.repository.db.Entity<T>,RESULT>
extends MultipleVarsYqlStatement<IN,T,RESULT>
Creates statement for SELECT ... WHERE PK IN (PK1, PK2, ...). PK can be both
a primary key and a key of secondary indexes. In the case of a secondary index, you must specify
the name of the index used.
For the entity:
@GlobalIndex(name = "index_by_keys", fields = {"k1", "k2"})
public class Sample implements Entity<Sample> {
Id id;
String value;
int k1;
String k2;
public static class Id implements Entity.Id<Sample> {
int id1;
int id2;
}
}
The statement will be :
DECLARE $Input AS List<Struct<id1:Int32?,id2:Int32?>>; SELECT t.`id1` AS `id1`, t.`id2` AS `id2`, t.`value` AS `value` FROM AS_TABLE($Input) AS k JOIN `sample` AS t ON t.`id1` = k.`id1` AND t.`id2` = k.`id2` ORDER BY id1 ASC, id2 ASC
If the entity ID is complex type, a part of the ID fields can be null.
They will be omitted in the query. For the given example,
if all ids have id2 == null, the statement will be:
DECLARE $Input AS List<Struct<id1:Int32?>>; SELECT t.`id1` AS `id1`, t.`id2` AS `id2`, t.`value` AS `value` FROM AS_TABLE($Input) AS k JOIN `sample` AS t ON t.`id1` = k.`id1` ORDER BY id1 ASC, id2 ASC
If orderBy specified as order by value descending, than statement will be:
DECLARE $Input AS List<Struct<id1:Int32?,id2:Int32?>>; SELECT t.`id1` AS `id1`, t.`id2` AS `id2`, t.`value` AS `value` FROM AS_TABLE($Input) AS k JOIN `sample` AS t ON t.`id1` = k.`id1` AND t.`id2` = k.`id2` ORDER BY value DESC
YDB restriction of the ORDER BY clause: ordering fields must be present in the resultSchema.
Statement also support filter expression. With the filter statement will will be as follows:
DECLARE $Input AS List<Struct<id1:Int32?,id2:Int32?>>; DECLARE $pred_0_value AS 'Utf8?'; SELECT `id1`, `id2`, `value` FROM ( SELECT t.`id1` AS `id1`, t.`id2` AS `id2`, t.`value` AS `value` FROM AS_TABLE($Input) AS k JOIN `sample` AS t ON t.`id1` = k.`id1` AND t.`id2` = k.`id2` ) WHERE value = $pred_0_value ORDER BY id1 ASC, id2 ASC
When using a secondary index, the statement will look like this:
DECLARE $Input AS List<Struct<`k1`:Int32,`k2`:Utf8>>; SELECT t.`value` AS `value` FROM AS_TABLE($Input) AS k JOIN `sample` VIEW `index_by_keys` AS t ON t.`k1` = k.`k1` AND t.`k2` = k.`k2`
-
Nested Class Summary
Nested classes/interfaces inherited from class tech.ydb.yoj.repository.ydb.statement.MultipleVarsYqlStatement
MultipleVarsYqlStatement.Simple<PARAMS,ENTITY extends tech.ydb.yoj.repository.db.Entity<ENTITY>> Nested classes/interfaces inherited from interface tech.ydb.yoj.repository.ydb.statement.Statement
Statement.QueryType -
Field Summary
Fields inherited from class tech.ydb.yoj.repository.ydb.statement.MultipleVarsYqlStatement
listNameFields inherited from class tech.ydb.yoj.repository.ydb.statement.YqlStatement
itemsCollector, ORDER_BY_ID_ASCENDING, resultSchema, resultSetReader, schema, tableName -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedFindInStatement(tech.ydb.yoj.repository.db.EntitySchema<T> schema, Schema<RESULT> resultSchema, Iterable<? extends tech.ydb.yoj.repository.db.Entity.Id<T>> ids, FilterExpression<T> filter, OrderExpression<T> orderBy, Integer limit) Creates newFindInStatementinstance with pagination.protectedFindInStatement(tech.ydb.yoj.repository.db.EntitySchema<T> schema, Schema<RESULT> resultSchema, String indexName, Iterable<V> keys, FilterExpression<T> filter, OrderExpression<T> orderBy, Integer limit) Creates newFindInStatementinstance with index usage and pagination. -
Method Summary
Modifier and TypeMethodDescriptionprotected StringReturns parameterized YQL for this query.Returns query type (for query merging purposes).protected StringoutNames()toDebugString(IN in) Returns debug representation of this query with the specified parameter values.toQueryParameters(IN in) Returns the query's parameter values as YDB protobuf structures.Methods inherited from class tech.ydb.yoj.repository.ydb.statement.MultipleVarsYqlStatement
toDebugParamsMethods inherited from class tech.ydb.yoj.repository.ydb.statement.YqlStatement
count, createTQueryParameter, delete, deleteAll, equals, escape, find, find, find, find, find, findAll, findAll, findIds, findIds, findIdsIn, findIn, findIn, findIn, findIn, findRange, findRange, getDeclaration, getInSchemaType, getTableName, getYqlType, getYqlValue, hashCode, insert, isPreparable, mergeParts, nameEqVars, predicateFrom, readResult, resolveParamNames, save, storeToCache, table, toString, updateMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface tech.ydb.yoj.repository.ydb.statement.Statement
readFromCache
-
Constructor Details
-
FindInStatement
protected FindInStatement(tech.ydb.yoj.repository.db.EntitySchema<T> schema, Schema<RESULT> resultSchema, Iterable<? extends tech.ydb.yoj.repository.db.Entity.Id<T>> ids, @Nullable FilterExpression<T> filter, @Nullable OrderExpression<T> orderBy, @Nullable Integer limit) Creates newFindInStatementinstance with pagination.- Parameters:
schema- entity schemaresultSchema- result schemaids- the ids of entities to loadfilter- optional additional filter expression, the filter is expected to filter by non-PK fieldsorderBy- order by expression for result sorting, order fields must be present in theresultSchema
-
FindInStatement
protected FindInStatement(tech.ydb.yoj.repository.db.EntitySchema<T> schema, Schema<RESULT> resultSchema, String indexName, Iterable<V> keys, @Nullable FilterExpression<T> filter, @Nullable OrderExpression<T> orderBy, @Nullable Integer limit) Creates newFindInStatementinstance with index usage and pagination.
-
-
Method Details
-
getQueryType
Description copied from interface:StatementReturns query type (for query merging purposes).- Returns:
- query type
-
getQuery
Description copied from interface:StatementReturns parameterized YQL for this query.- Parameters:
tablespace- base path for all tables referenced in the query- Returns:
- YQL
-
getParams
-
toQueryParameters
Description copied from interface:StatementReturns the query's parameter values as YDB protobuf structures.- Specified by:
toQueryParametersin interfaceStatement<IN,T extends tech.ydb.yoj.repository.db.Entity<T>> - Overrides:
toQueryParametersin classMultipleVarsYqlStatement<IN,T extends tech.ydb.yoj.repository.db.Entity<T>, RESULT> - Parameters:
in- parameter values Might benulldepending on the statement type, e.g. for DELETE statements.- Returns:
- map: parameter name -> value as protobuf
-
declarations
- Overrides:
declarationsin classMultipleVarsYqlStatement<IN,T extends tech.ydb.yoj.repository.db.Entity<T>, RESULT>
-
outNames
-
flattenInputVariables
- Specified by:
flattenInputVariablesin classMultipleVarsYqlStatement<IN,T extends tech.ydb.yoj.repository.db.Entity<T>, RESULT>
-
toDebugString
Description copied from interface:StatementReturns debug representation of this query with the specified parameter values.- Parameters:
in- parameter values. Might benulldepending on the statement type, e.g. for DELETE statements.- Returns:
- debug representation of the query parameterized with
params
-