alex-plekhanov commented on code in PR #13569:
URL: https://github.com/apache/ignite/pull/13569#discussion_r4073048856
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/TableFunctionScan.java:
##########
@@ -58,14 +70,35 @@ private Row convertToRow(Object rowContainer) {
throw new IgniteSQLException("Unable to process table function
data: row type is neither Collection or Object[].");
Object[] rowArr = rowContainer.getClass() == Object[].class
- ? (Object[])rowContainer
+ ? ((Object[])rowContainer).clone()
Review Comment:
Minor: We can check if any type is convertible (for example in constructor)
and clone array only if required.
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/UserDefinedFunctionsIntegrationTest.java:
##########
@@ -492,6 +504,383 @@ public void testBigDecimalFunctionArgument() {
assertQuery("SELECT udf.decimalToInt(5.3)").returns(5).check();
}
+ /** */
+ @Test
+ public void testObjectTableFunctionResult() {
+ client.getOrCreateCache(new
CacheConfiguration<>("object-table-functions")
+ .setSqlSchema("PUBLIC")
+ .setSqlFunctionClasses(CustomTypeFunctionsLibrary.class));
+
+ Object[] exp = temporalValues();
+
+ assertQuery("SELECT * FROM objectTableValues()")
+ .withResultChecker(rows -> {
+ assertEquals(1, rows.size());
+ assertEquals(exp.length, rows.get(0).size());
+
+ for (int i = 0; i < exp.length; i++) {
+ Object actual = rows.get(0).get(i);
+
+ assertEquals("Unexpected value type at index " + i,
exp[i].getClass(), actual.getClass());
+ assertEqualsArraysAware("Unexpected value at index " + i,
exp[i], actual);
Review Comment:
Minor: There are no arrays in result, assertEqualsArraysAware is confusing.
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/util/TypeUtilsTest.java:
##########
@@ -0,0 +1,143 @@
+/*
+ * 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.util;
+
+import java.lang.reflect.Type;
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.GregorianCalendar;
+import java.util.Locale;
+import java.util.TimeZone;
+import org.apache.calcite.DataContext;
+import org.apache.calcite.DataContexts;
+import org.apache.calcite.util.DateString;
+import org.apache.calcite.util.TimeString;
+import org.apache.calcite.util.TimestampString;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
+/** */
+public class TypeUtilsTest {
+ /** */
+ @Test
+ public void testLocalDateConversion() {
+ for (String date : new String[] {
+ "0001-01-01", "1500-01-02", "1582-10-10", "1969-12-31",
"1970-01-01", "2011-12-30", "9999-12-31"
+ }) {
+ checkConversion(LocalDate.parse(date), new
DateString(date).getDaysSinceEpoch(), Date.class);
+ }
+ }
+
+ /** */
+ @Test
+ public void testLocalTimeConversion() {
+ for (String time : new String[] {"00:00:00", "02:30:00",
"12:34:56.123", "23:59:59.999"})
+ checkConversion(LocalTime.parse(time), new
TimeString(time).getMillisOfDay(), Time.class);
+ }
+
+ /** */
+ @Test
+ public void testLocalDateTimeConversion() {
+ for (String ts : new String[] {
+ "0001-01-01 00:00:00", "1500-01-02 03:04:05", "1582-10-10
12:34:56", "1969-12-31 23:59:59.999",
+ "1970-01-01 00:00:00", "2011-12-30 12:34:56", "2021-03-14
02:30:00.123", "2021-11-07 01:30:00.123"
+ }) {
+ checkConversion(LocalDateTime.parse(ts.replace(' ', 'T')), new
TimestampString(ts).getMillisSinceEpoch(),
+ Timestamp.class);
+ }
+ }
+
+ /** */
+ @Test
+ public void testSqlDateConversion() {
+ for (String date : new String[] {
+ "0001-01-01", "1500-01-02", "1582-10-04", "1582-10-15",
"1969-12-31", "1970-01-01", "9999-12-31"
+ }) {
Review Comment:
Redundant braces
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/util/TypeUtilsTest.java:
##########
@@ -0,0 +1,143 @@
+/*
+ * 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.util;
+
+import java.lang.reflect.Type;
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.GregorianCalendar;
+import java.util.Locale;
+import java.util.TimeZone;
+import org.apache.calcite.DataContext;
+import org.apache.calcite.DataContexts;
+import org.apache.calcite.util.DateString;
+import org.apache.calcite.util.TimeString;
+import org.apache.calcite.util.TimestampString;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
+/** */
+public class TypeUtilsTest {
+ /** */
+ @Test
+ public void testLocalDateConversion() {
+ for (String date : new String[] {
+ "0001-01-01", "1500-01-02", "1582-10-10", "1969-12-31",
"1970-01-01", "2011-12-30", "9999-12-31"
+ }) {
Review Comment:
Redundant braces
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/util/TypeUtils.java:
##########
@@ -528,4 +570,11 @@ public static RexNode toRexLiteral(Object dfltVal,
RelDataType type, DataContext
return rexBuilder.makeLiteral(dfltVal, type, true);
}
+
+ /** */
+ private static TimeZone timeZone(DataContext ctx) {
+ TimeZone tz = DataContext.Variable.TIME_ZONE.get(ctx);
+
+ return tz != null ? tz : TimeZone.getDefault();
Review Comment:
Looks like DataContext.Variable.TIME_ZONE.get(ctx) is never can be null, why
do we need this new check?
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/util/TypeUtils.java:
##########
@@ -514,7 +543,20 @@ else if (UUID.class.equals(storageType)) {
/** */
private static long fromLocalTs(DataContext ctx, long ts) {
- TimeZone tz = DataContext.Variable.TIME_ZONE.get(ctx);
+ if (ts < GREGORIAN_CUTOVER) {
Review Comment:
This is more correct fix for
https://issues.apache.org/jira/browse/IGNITE-23772 ticket. Maybe we should
check tests from PR for this ticket and if all these tests pass, close
IGNITE-23772 after your fix?
--
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]