zstan commented on code in PR #13543:
URL: https://github.com/apache/ignite/pull/13543#discussion_r3956024252
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/exec/rel/ExecutionTest.java:
##########
@@ -63,6 +79,51 @@ public class ExecutionTest extends AbstractExecutionTest {
super.setup();
}
+ /** */
+ @Test
+ public void testTableFunctionOtherValues() {
+ checkTableFunctionOtherValues(new
BasicSqlType(IgniteTypeSystem.INSTANCE, SqlTypeName.OTHER));
+ checkTableFunctionOtherValues(new OtherType(true));
+ }
+
+ /** */
+ private void checkTableFunctionOtherValues(RelDataType colType) {
+ ExecutionContext<Object[]> ctx = executionContext();
+
+ // Bypass type canonization to test both representations of OTHER
regardless of the shared type cache state.
+ RelDataType rowType = new RelRecordType(Collections.singletonList(new
RelDataTypeFieldImpl("V", 0, colType)));
+
+ Object[] vals = {
+ new byte[] {1, 2, 3},
+ new java.util.Date(0),
+ Date.valueOf("2020-01-01"),
+ Time.valueOf("02:03:04"),
+ Timestamp.valueOf("2020-01-01 02:03:04"),
+ LocalDate.of(2020, 1, 1),
+ LocalTime.of(2, 3, 4),
+ LocalDateTime.of(2020, 1, 1, 2, 3, 4),
+ Duration.ofHours(2),
+ Period.ofMonths(3),
+ null
+ };
+
+ for (Object val : vals) {
+ Object[] row = {val};
+
+ for (Object container : new Object[] {row,
Collections.singletonList(val)}) {
+ TableFunctionScan<Object[]> scan = new
TableFunctionScan<>(ctx, rowType,
+ () -> Collections.singletonList(container),
ctx.rowHandler().factory(ctx.getTypeFactory(), rowType));
+
+ Object[] res = scan.iterator().next();
+
+ assertNotSame(row, res);
+ assertEquals(1, res.length);
+ assertSame(val, res[0]);
+ assertSame(val, row[0]);
Review Comment:
redundant
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/IgniteFunctionParameter.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.exec.exp;
+
+import java.util.List;
+import org.apache.calcite.adapter.java.JavaTypeFactory;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.schema.FunctionParameter;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.ignite.internal.processors.query.calcite.type.OtherType;
+
+/**
+ * Reflective Java function parameter represented with a SQL type.
+ *
+ * <p>The SQL representation is required to validate user-defined function
arguments and to convert literal arguments
+ * while deriving a table function row type.
+ */
+final class IgniteFunctionParameter implements FunctionParameter {
+ /** Original function parameter. */
+ private final FunctionParameter delegate;
+
+ /**
+ * Constructor.
+ *
+ * @param delegate Original function parameter.
+ */
+ private IgniteFunctionParameter(FunctionParameter delegate) {
+ this.delegate = delegate;
+ }
+
+ /** Returns function parameters represented with SQL types. */
+ static List<FunctionParameter> toSql(List<FunctionParameter> parameters) {
+ return
parameters.stream().map(IgniteFunctionParameter::toSql).toList();
+ }
+
+ /** Returns a function parameter represented with a SQL type. */
+ static FunctionParameter toSql(FunctionParameter parameter) {
+ return new IgniteFunctionParameter(parameter);
+ }
+
+ /** {@inheritDoc} */
+ @Override public int getOrdinal() {
+ return delegate.getOrdinal();
+ }
+
+ /** {@inheritDoc} */
+ @Override public String getName() {
+ return delegate.getName();
+ }
+
+ /** {@inheritDoc} */
+ @Override public RelDataType getType(RelDataTypeFactory typeFactory) {
+ JavaTypeFactory tf = (JavaTypeFactory)typeFactory;
+ RelDataType type = tf.toSql(delegate.getType(typeFactory));
+
+ // Prevent the validator from replacing OTHER with a structured type
derived from a dynamic parameter value.
+ return type.getSqlTypeName() == SqlTypeName.OTHER ? new
OtherType(type.isNullable()) : type;
Review Comment:
optimization: if type.getSqlTypeName() == SqlTypeName.OTHER - above derived
`RelDataType type` will be dropped
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/LogicalRelImplementor.java:
##########
@@ -788,7 +788,7 @@ else if (rel instanceof Intersect)
RowFactory<Row> rowFactory =
ctx.rowHandler().factory(ctx.getTypeFactory(), rowType);
- return new ScanNode<>(ctx, rowType, new TableFunctionScan<>(rowType,
dataSupplier, rowFactory));
+ return new ScanNode<>(ctx, rowType, new TableFunctionScan<>(ctx,
rowType, dataSupplier, rowFactory));
Review Comment:
rowFactory = ctx.rowHandler().factory(ctx.getTypeFactory(), rowType); -
gathered from `ctx` and `rowType` that already passed, so - no need to pass
`rowFactory` as param? Now - it can be derived inside ScanNode constructor.
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ConverterUtils.java:
##########
@@ -111,6 +116,9 @@ else if (targetType == java.sql.Timestamp.class) {
if (isA(fromType, Primitive.LONG))
return
Expressions.call(BuiltInMethod.INTERNAL_TO_TIMESTAMP.method, operand);
}
+ else if (targetType == byte[].class && fromType == ByteString.class)
Review Comment:
sorry, but still miss it ( do we have a test for it ? suggest it plz ?
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/ConverterUtils.java:
##########
@@ -145,6 +150,66 @@ static List<Expression> fromInternal(Class<?>[]
targetTypes,
return list;
}
+ /** */
+ static List<Expression> fromInternal(RexToLixTranslator translator,
+ Class<?>[] targetTypes,
+ List<Expression> expressions
+ ) {
+ final List<Expression> list = new ArrayList<>();
Review Comment:
```suggestion
final List<Expression> list = new ArrayList<>(expressions.size());
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]