Package com.linkedin.venice.client.store
Class AbstractAvroComputeRequestBuilder<K>
- java.lang.Object
-
- com.linkedin.venice.client.store.AbstractAvroComputeRequestBuilder<K>
-
- Type Parameters:
K
-
- All Implemented Interfaces:
ComputeRequestBuilder<K>
- Direct Known Subclasses:
AvroComputeRequestBuilderV3
public abstract class AbstractAvroComputeRequestBuilder<K> extends java.lang.Object implements ComputeRequestBuilder<K>
This abstract class contains all the common field and APIs for compute request builder; for each new compute request version, there will be a new builder class that extends this class and the new builder will include customized fields and APIs.
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.apache.avro.Schema
COSINE_SIMILARITY_RESULT_SCHEMA
protected static java.lang.String
COSINE_SIMILARITY_SPEC
protected static org.apache.avro.Schema
DOT_PRODUCT_RESULT_SCHEMA
protected static java.lang.String
DOT_PRODUCT_SPEC
protected static org.apache.avro.Schema
HADAMARD_PRODUCT_RESULT_SCHEMA
protected static java.lang.String
HADAMARD_PRODUCT_SPEC
protected org.apache.avro.Schema
latestValueSchema
protected int
latestValueSchemaId
protected static java.lang.String
PROJECTION_SPEC
protected static java.util.Map<java.util.Map<java.lang.String,java.lang.Object>,SchemaAndToString>
RESULT_SCHEMA_CACHE
protected java.lang.String
resultSchemaName
protected AvroGenericReadComputeStoreClient
storeClient
-
Constructor Summary
Constructors Constructor Description AbstractAvroComputeRequestBuilder(AvroGenericReadComputeStoreClient storeClient, SchemaReader schemaReader)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
checkComputeFieldValidity(java.lang.String computeFieldName, java.lang.String resultFieldName, java.util.Set<java.lang.String> resultFieldsSet, ComputeOperationType computeType)
protected java.util.Set<java.lang.String>
commonValidityCheck()
Compute operation validity check for projections, dot-product and cosine-similarity.ComputeRequestBuilder<K>
cosineSimilarity(java.lang.String inputFieldName, java.util.List<java.lang.Float> cosSimilarityParam, java.lang.String resultFieldName)
Setup cosine-similarity operation.ComputeRequestBuilder<K>
dotProduct(java.lang.String inputFieldName, java.util.List<java.lang.Float> dotProductParam, java.lang.String resultFieldName)
Setup dot-product operation.java.util.concurrent.CompletableFuture<java.util.Map<K,ComputeGenericRecord>>
execute(java.util.Set<K> keys)
Send compute request to Venice, and this should be the last step of the compute specification.protected ComputeRequestWrapper
generateComputeRequest(SchemaAndToString resultSchema, boolean originallyStreaming)
protected java.util.Map<java.lang.String,java.lang.Object>
getCommonComputeSpec()
Generate compute spec for projections, dot-product and cosine-similarity.protected java.util.List<org.apache.avro.Schema.Field>
getCommonResultFields()
Generate compute result schema fields for projections, dot-product and cosine-similarity.protected java.util.List<ComputeOperation>
getComputeRequestOperations()
Generate compute operations for projections, dot-product and cosine-similarity.protected SchemaAndToString
getResultSchema()
ComputeRequestBuilder<K>
hadamardProduct(java.lang.String inputFieldName, java.util.List<java.lang.Float> hadamardProductParam, java.lang.String resultFieldName)
Setup hadamard-product operation; if this api is invoked, use version 2 in the compute request version header.ComputeRequestBuilder<K>
project(java.lang.String... fieldNames)
Setup project fields, and right now only top-level fields are supported.ComputeRequestBuilder<K>
project(java.util.Collection<java.lang.String> fieldNames)
Setup project fields, and right now only top-level fields are supported.AbstractAvroComputeRequestBuilder<K>
setStats(java.util.Optional<ClientStats> streamingStats)
AbstractAvroComputeRequestBuilder<K>
setTime(io.tehuti.utils.Time time)
test-onlyAbstractAvroComputeRequestBuilder<K>
setValidateProjectionFields(boolean projectionFieldValidation)
java.util.concurrent.CompletableFuture<VeniceResponseMap<K,ComputeGenericRecord>>
streamingExecute(java.util.Set<K> keys)
Send compute request to Venice, and this should be the last step of the compute specification.void
streamingExecute(java.util.Set<K> keys, StreamingCallback<K,ComputeGenericRecord> callback)
Streaming interface forComputeRequestBuilder.execute(Set)
, and you could find more info inStreamingCallback
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.linkedin.venice.client.store.ComputeRequestBuilder
count, executeWithFilter
-
-
-
-
Field Detail
-
RESULT_SCHEMA_CACHE
protected static final java.util.Map<java.util.Map<java.lang.String,java.lang.Object>,SchemaAndToString> RESULT_SCHEMA_CACHE
-
PROJECTION_SPEC
protected static final java.lang.String PROJECTION_SPEC
- See Also:
- Constant Field Values
-
DOT_PRODUCT_SPEC
protected static final java.lang.String DOT_PRODUCT_SPEC
- See Also:
- Constant Field Values
-
COSINE_SIMILARITY_SPEC
protected static final java.lang.String COSINE_SIMILARITY_SPEC
- See Also:
- Constant Field Values
-
HADAMARD_PRODUCT_SPEC
protected static final java.lang.String HADAMARD_PRODUCT_SPEC
- See Also:
- Constant Field Values
-
HADAMARD_PRODUCT_RESULT_SCHEMA
protected static final org.apache.avro.Schema HADAMARD_PRODUCT_RESULT_SCHEMA
-
DOT_PRODUCT_RESULT_SCHEMA
protected static final org.apache.avro.Schema DOT_PRODUCT_RESULT_SCHEMA
-
COSINE_SIMILARITY_RESULT_SCHEMA
protected static final org.apache.avro.Schema COSINE_SIMILARITY_RESULT_SCHEMA
-
storeClient
protected final AvroGenericReadComputeStoreClient storeClient
-
latestValueSchemaId
protected final int latestValueSchemaId
-
latestValueSchema
protected final org.apache.avro.Schema latestValueSchema
-
resultSchemaName
protected final java.lang.String resultSchemaName
-
-
Constructor Detail
-
AbstractAvroComputeRequestBuilder
public AbstractAvroComputeRequestBuilder(AvroGenericReadComputeStoreClient storeClient, SchemaReader schemaReader)
-
-
Method Detail
-
setTime
public AbstractAvroComputeRequestBuilder<K> setTime(io.tehuti.utils.Time time)
test-only
-
setStats
public AbstractAvroComputeRequestBuilder<K> setStats(java.util.Optional<ClientStats> streamingStats)
-
setValidateProjectionFields
public AbstractAvroComputeRequestBuilder<K> setValidateProjectionFields(boolean projectionFieldValidation)
-
project
public ComputeRequestBuilder<K> project(java.lang.String... fieldNames) throws VeniceClientException
Description copied from interface:ComputeRequestBuilder
Setup project fields, and right now only top-level fields are supported.- Specified by:
project
in interfaceComputeRequestBuilder<K>
- Returns:
- Throws:
VeniceClientException
-
project
public ComputeRequestBuilder<K> project(java.util.Collection<java.lang.String> fieldNames) throws VeniceClientException
Description copied from interface:ComputeRequestBuilder
Setup project fields, and right now only top-level fields are supported.- Specified by:
project
in interfaceComputeRequestBuilder<K>
- Returns:
- Throws:
VeniceClientException
-
dotProduct
public ComputeRequestBuilder<K> dotProduct(java.lang.String inputFieldName, java.util.List<java.lang.Float> dotProductParam, java.lang.String resultFieldName) throws VeniceClientException
Description copied from interface:ComputeRequestBuilder
Setup dot-product operation.- Specified by:
dotProduct
in interfaceComputeRequestBuilder<K>
- Parameters:
inputFieldName
- : top-level field in the value record as the input of dot-product operationdotProductParam
- : dot-product paramresultFieldName
- : result field name in the response record- Returns:
- Throws:
VeniceClientException
-
cosineSimilarity
public ComputeRequestBuilder<K> cosineSimilarity(java.lang.String inputFieldName, java.util.List<java.lang.Float> cosSimilarityParam, java.lang.String resultFieldName) throws VeniceClientException
Description copied from interface:ComputeRequestBuilder
Setup cosine-similarity operation.- Specified by:
cosineSimilarity
in interfaceComputeRequestBuilder<K>
- Parameters:
inputFieldName
- : top-level field in the value record as the input of cosine-similarity operationcosSimilarityParam
- : cosine-similarity paramresultFieldName
- : result field name in the response record- Returns:
- Throws:
VeniceClientException
-
getCommonComputeSpec
protected java.util.Map<java.lang.String,java.lang.Object> getCommonComputeSpec()
Generate compute spec for projections, dot-product and cosine-similarity.- Returns:
- common compute spec
-
commonValidityCheck
protected java.util.Set<java.lang.String> commonValidityCheck()
Compute operation validity check for projections, dot-product and cosine-similarity.- Returns:
- a set of existing operations result field name
-
getCommonResultFields
protected java.util.List<org.apache.avro.Schema.Field> getCommonResultFields()
Generate compute result schema fields for projections, dot-product and cosine-similarity.- Returns:
- a list of existing compute result schema fields
-
getComputeRequestOperations
protected java.util.List<ComputeOperation> getComputeRequestOperations()
Generate compute operations for projections, dot-product and cosine-similarity.- Returns:
- a list of existing compute operations
-
execute
public java.util.concurrent.CompletableFuture<java.util.Map<K,ComputeGenericRecord>> execute(java.util.Set<K> keys) throws VeniceClientException
Description copied from interface:ComputeRequestBuilder
Send compute request to Venice, and this should be the last step of the compute specification.- Specified by:
execute
in interfaceComputeRequestBuilder<K>
- Parameters:
keys
- : keys for the candidate records- Returns:
- Throws:
VeniceClientException
-
streamingExecute
public java.util.concurrent.CompletableFuture<VeniceResponseMap<K,ComputeGenericRecord>> streamingExecute(java.util.Set<K> keys)
Description copied from interface:ComputeRequestBuilder
Send compute request to Venice, and this should be the last step of the compute specification. The difference between this function and the previousComputeRequestBuilder.execute(Set)
is that this function will return the available response instead of throwing aTimeoutException
when timeout happens: streamingExecute(keys).get(timeout, units);- Specified by:
streamingExecute
in interfaceComputeRequestBuilder<K>
- Returns:
-
streamingExecute
public void streamingExecute(java.util.Set<K> keys, StreamingCallback<K,ComputeGenericRecord> callback) throws VeniceClientException
Description copied from interface:ComputeRequestBuilder
Streaming interface forComputeRequestBuilder.execute(Set)
, and you could find more info inStreamingCallback
.- Specified by:
streamingExecute
in interfaceComputeRequestBuilder<K>
- Throws:
VeniceClientException
-
checkComputeFieldValidity
protected void checkComputeFieldValidity(java.lang.String computeFieldName, java.lang.String resultFieldName, java.util.Set<java.lang.String> resultFieldsSet, ComputeOperationType computeType)
-
getResultSchema
protected SchemaAndToString getResultSchema()
-
hadamardProduct
public ComputeRequestBuilder<K> hadamardProduct(java.lang.String inputFieldName, java.util.List<java.lang.Float> hadamardProductParam, java.lang.String resultFieldName) throws VeniceClientException
Description copied from interface:ComputeRequestBuilder
Setup hadamard-product operation; if this api is invoked, use version 2 in the compute request version header.- Specified by:
hadamardProduct
in interfaceComputeRequestBuilder<K>
- Parameters:
inputFieldName
- : top-level field in the value record as the input of hadamard-product operationhadamardProductParam
- : hadamard-product paramresultFieldName
- : result field name in the response record- Returns:
- Throws:
VeniceClientException
-
generateComputeRequest
protected ComputeRequestWrapper generateComputeRequest(SchemaAndToString resultSchema, boolean originallyStreaming)
-
-