korlov42 commented on code in PR #2368: URL: https://github.com/apache/ignite-3/pull/2368#discussion_r1288457210
########## modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/util/IgniteCustomAssigmentsRules.java: ########## @@ -0,0 +1,255 @@ +/* + * 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.sql.engine.util; + +import static org.apache.calcite.sql.type.SqlTypeName.APPROX_TYPES; +import static org.apache.calcite.sql.type.SqlTypeName.BINARY_TYPES; +import static org.apache.calcite.sql.type.SqlTypeName.CHAR_TYPES; +import static org.apache.calcite.sql.type.SqlTypeName.DAY_INTERVAL_TYPES; +import static org.apache.calcite.sql.type.SqlTypeName.EXACT_TYPES; +import static org.apache.calcite.sql.type.SqlTypeName.FRACTIONAL_TYPES; +import static org.apache.calcite.sql.type.SqlTypeName.YEAR_INTERVAL_TYPES; + +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; +import com.google.common.util.concurrent.UncheckedExecutionException; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ExecutionException; +import org.apache.calcite.sql.type.SqlTypeAssignmentRule; +import org.apache.calcite.sql.type.SqlTypeCoercionRule; +import org.apache.calcite.sql.type.SqlTypeMappingRule; +import org.apache.calcite.sql.type.SqlTypeMappingRules; +import org.apache.calcite.sql.type.SqlTypeName; +import org.apache.calcite.util.Util; + +/** + * Rules that determine whether a type is assignable from another type. + * These rules specify the conversion matrix with explicit CAST. + * Calcite native rules {@link SqlTypeCoercionRule} and {@link SqlTypeAssignmentRule} are not satisfy SQL standard rules, + * thus custom implementation is implemented. + */ +public class IgniteCustomAssigmentsRules implements SqlTypeMappingRule { + private final Map<SqlTypeName, ImmutableSet<SqlTypeName>> map; + + private static final IgniteCustomAssigmentsRules INSTANCE; + + private IgniteCustomAssigmentsRules( + Map<SqlTypeName, ImmutableSet<SqlTypeName>> map) { + this.map = ImmutableMap.copyOf(map); + } + + static { + IgniteCustomAssigmentsRules.Builder rules = builder(); + + Set<SqlTypeName> rule = EnumSet.noneOf(SqlTypeName.class); + + // IntervalYearMonth is assignable from... + for (SqlTypeName interval : YEAR_INTERVAL_TYPES) { + rules.add(interval, YEAR_INTERVAL_TYPES); Review Comment: according to the CAST matrix, YM intervals can be casted from Exact Numerics and chars. Why do omit these options? the same for DT intervals. I believe you need to double check the matrix ########## modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItSqlOperatorsTest.java: ########## @@ -276,7 +276,6 @@ public void testOtherFunctions() { assertExpression("GREATEST('a', 'b')").returns("b").check(); assertExpression("COMPRESS('')::VARCHAR").returns("").check(); assertExpression("OCTET_LENGTH(x'01')").returns(1).check(); - assertExpression("CAST(INTERVAL 1 SECONDS AS INT)").returns(1).check(); // Converted to REINTERPRED. Review Comment: this case seems valid, why have you removed this>? ########## modules/runner/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItIntervalTest.java: ########## @@ -70,25 +70,29 @@ public void testIntervalResult() { */ @Test public void testIntervalIntCast() { Review Comment: why all these casts are not allowed anymore? -- 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]
