Skip to content

Commit

Permalink
Pass parameters row as Block
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiafi committed May 27, 2022
1 parent dce2a6e commit e970629
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.trino.operator.scalar.ChoicesScalarFunctionImplementation;
import io.trino.operator.scalar.ScalarFunctionImplementation;
import io.trino.spi.TrinoException;
import io.trino.spi.block.Block;
import io.trino.spi.connector.ConnectorSession;
import io.trino.spi.type.Type;
import io.trino.spi.type.TypeManager;
Expand Down Expand Up @@ -53,7 +54,7 @@ public class JsonExistsFunction
extends SqlScalarFunction
{
public static final String JSON_EXISTS_FUNCTION_NAME = "$json_exists";
private static final MethodHandle METHOD_HANDLE = methodHandle(JsonExistsFunction.class, "jsonExists", FunctionManager.class, Metadata.class, TypeManager.class, Type.class, ConnectorSession.class, JsonNode.class, IrJsonPath.class, Object.class, long.class);
private static final MethodHandle METHOD_HANDLE = methodHandle(JsonExistsFunction.class, "jsonExists", FunctionManager.class, Metadata.class, TypeManager.class, Type.class, ConnectorSession.class, JsonNode.class, IrJsonPath.class, Block.class, long.class);
private static final TrinoException INPUT_ARGUMENT_ERROR = new JsonInputConversionError("malformed input argument to JSON_EXISTS function");
private static final TrinoException PATH_PARAMETER_ERROR = new JsonInputConversionError("malformed JSON path parameter to JSON_EXISTS function");

Expand Down Expand Up @@ -106,7 +107,7 @@ public static Boolean jsonExists(
ConnectorSession session,
JsonNode inputExpression,
IrJsonPath jsonPath,
Object parametersRow,
Block parametersRow,
long errorBehavior)
{
if (inputExpression.equals(JSON_ERROR)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.trino.operator.scalar.ChoicesScalarFunctionImplementation;
import io.trino.operator.scalar.ScalarFunctionImplementation;
import io.trino.spi.TrinoException;
import io.trino.spi.block.Block;
import io.trino.spi.connector.ConnectorSession;
import io.trino.spi.type.Type;
import io.trino.spi.type.TypeManager;
Expand Down Expand Up @@ -61,7 +62,7 @@ public class JsonQueryFunction
extends SqlScalarFunction
{
public static final String JSON_QUERY_FUNCTION_NAME = "$json_query";
private static final MethodHandle METHOD_HANDLE = methodHandle(JsonQueryFunction.class, "jsonQuery", FunctionManager.class, Metadata.class, TypeManager.class, Type.class, ConnectorSession.class, JsonNode.class, IrJsonPath.class, Object.class, long.class, long.class, long.class);
private static final MethodHandle METHOD_HANDLE = methodHandle(JsonQueryFunction.class, "jsonQuery", FunctionManager.class, Metadata.class, TypeManager.class, Type.class, ConnectorSession.class, JsonNode.class, IrJsonPath.class, Block.class, long.class, long.class, long.class);
private static final JsonNode EMPTY_ARRAY_RESULT = new ArrayNode(JsonNodeFactory.instance);
private static final JsonNode EMPTY_OBJECT_RESULT = new ObjectNode(JsonNodeFactory.instance);
private static final TrinoException INPUT_ARGUMENT_ERROR = new JsonInputConversionError("malformed input argument to JSON_QUERY function");
Expand Down Expand Up @@ -124,7 +125,7 @@ public static JsonNode jsonQuery(
ConnectorSession session,
JsonNode inputExpression,
IrJsonPath jsonPath,
Object parametersRow,
Block parametersRow,
long wrapperBehavior,
long emptyBehavior,
long errorBehavior)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import io.trino.operator.scalar.ChoicesScalarFunctionImplementation;
import io.trino.operator.scalar.ScalarFunctionImplementation;
import io.trino.spi.TrinoException;
import io.trino.spi.block.Block;
import io.trino.spi.connector.ConnectorSession;
import io.trino.spi.type.Type;
import io.trino.spi.type.TypeManager;
Expand Down Expand Up @@ -65,11 +66,11 @@ public class JsonValueFunction
extends SqlScalarFunction
{
public static final String JSON_VALUE_FUNCTION_NAME = "$json_value";
private static final MethodHandle METHOD_HANDLE_LONG = methodHandle(JsonValueFunction.class, "jsonValueLong", FunctionManager.class, Metadata.class, TypeManager.class, Type.class, Type.class, ConnectorSession.class, JsonNode.class, IrJsonPath.class, Object.class, long.class, Long.class, long.class, Long.class);
private static final MethodHandle METHOD_HANDLE_DOUBLE = methodHandle(JsonValueFunction.class, "jsonValueDouble", FunctionManager.class, Metadata.class, TypeManager.class, Type.class, Type.class, ConnectorSession.class, JsonNode.class, IrJsonPath.class, Object.class, long.class, Double.class, long.class, Double.class);
private static final MethodHandle METHOD_HANDLE_BOOLEAN = methodHandle(JsonValueFunction.class, "jsonValueBoolean", FunctionManager.class, Metadata.class, TypeManager.class, Type.class, Type.class, ConnectorSession.class, JsonNode.class, IrJsonPath.class, Object.class, long.class, Boolean.class, long.class, Boolean.class);
private static final MethodHandle METHOD_HANDLE_SLICE = methodHandle(JsonValueFunction.class, "jsonValueSlice", FunctionManager.class, Metadata.class, TypeManager.class, Type.class, Type.class, ConnectorSession.class, JsonNode.class, IrJsonPath.class, Object.class, long.class, Slice.class, long.class, Slice.class);
private static final MethodHandle METHOD_HANDLE = methodHandle(JsonValueFunction.class, "jsonValue", FunctionManager.class, Metadata.class, TypeManager.class, Type.class, Type.class, ConnectorSession.class, JsonNode.class, IrJsonPath.class, Object.class, long.class, Object.class, long.class, Object.class);
private static final MethodHandle METHOD_HANDLE_LONG = methodHandle(JsonValueFunction.class, "jsonValueLong", FunctionManager.class, Metadata.class, TypeManager.class, Type.class, Type.class, ConnectorSession.class, JsonNode.class, IrJsonPath.class, Block.class, long.class, Long.class, long.class, Long.class);
private static final MethodHandle METHOD_HANDLE_DOUBLE = methodHandle(JsonValueFunction.class, "jsonValueDouble", FunctionManager.class, Metadata.class, TypeManager.class, Type.class, Type.class, ConnectorSession.class, JsonNode.class, IrJsonPath.class, Block.class, long.class, Double.class, long.class, Double.class);
private static final MethodHandle METHOD_HANDLE_BOOLEAN = methodHandle(JsonValueFunction.class, "jsonValueBoolean", FunctionManager.class, Metadata.class, TypeManager.class, Type.class, Type.class, ConnectorSession.class, JsonNode.class, IrJsonPath.class, Block.class, long.class, Boolean.class, long.class, Boolean.class);
private static final MethodHandle METHOD_HANDLE_SLICE = methodHandle(JsonValueFunction.class, "jsonValueSlice", FunctionManager.class, Metadata.class, TypeManager.class, Type.class, Type.class, ConnectorSession.class, JsonNode.class, IrJsonPath.class, Block.class, long.class, Slice.class, long.class, Slice.class);
private static final MethodHandle METHOD_HANDLE = methodHandle(JsonValueFunction.class, "jsonValue", FunctionManager.class, Metadata.class, TypeManager.class, Type.class, Type.class, ConnectorSession.class, JsonNode.class, IrJsonPath.class, Block.class, long.class, Object.class, long.class, Object.class);
private static final TrinoException INPUT_ARGUMENT_ERROR = new JsonInputConversionError("malformed input argument to JSON_VALUE function");
private static final TrinoException PATH_PARAMETER_ERROR = new JsonInputConversionError("malformed JSON path parameter to JSON_VALUE function");
private static final TrinoException NO_ITEMS = new JsonValueResultError("JSON path found no items");
Expand Down Expand Up @@ -153,7 +154,7 @@ public static Long jsonValueLong(
ConnectorSession session,
JsonNode inputExpression,
IrJsonPath jsonPath,
Object parametersRow,
Block parametersRow,
long emptyBehavior,
Long emptyDefault,
long errorBehavior,
Expand All @@ -172,7 +173,7 @@ public static Double jsonValueDouble(
ConnectorSession session,
JsonNode inputExpression,
IrJsonPath jsonPath,
Object parametersRow,
Block parametersRow,
long emptyBehavior,
Double emptyDefault,
long errorBehavior,
Expand All @@ -191,7 +192,7 @@ public static Boolean jsonValueBoolean(
ConnectorSession session,
JsonNode inputExpression,
IrJsonPath jsonPath,
Object parametersRow,
Block parametersRow,
long emptyBehavior,
Boolean emptyDefault,
long errorBehavior,
Expand All @@ -210,7 +211,7 @@ public static Slice jsonValueSlice(
ConnectorSession session,
JsonNode inputExpression,
IrJsonPath jsonPath,
Object parametersRow,
Block parametersRow,
long emptyBehavior,
Slice emptyDefault,
long errorBehavior,
Expand All @@ -229,7 +230,7 @@ public static Object jsonValue(
ConnectorSession session,
JsonNode inputExpression,
IrJsonPath jsonPath,
Object parametersRow,
Block parametersRow,
long emptyBehavior,
Object emptyDefault,
long errorBehavior,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,14 @@ private ParameterUtil() {}
* @param parametersRow a Block containing parameters
* @return an array containing the converted values
*/
public static Object[] getParametersArray(Type parametersRowType, Object parametersRow)
public static Object[] getParametersArray(Type parametersRowType, Block parametersRow)
{
if (JSON_NO_PARAMETERS_ROW_TYPE.equals(parametersRowType)) {
return new Object[] {};
}

RowType rowType = (RowType) parametersRowType;
Block row = (Block) parametersRow;
List<Block> parameterBlocks = row.getChildren();
List<Block> parameterBlocks = parametersRow.getChildren();

Object[] array = new Object[rowType.getFields().size()];
for (int i = 0; i < rowType.getFields().size(); i++) {
Expand Down

0 comments on commit e970629

Please sign in to comment.