Skip to content
Permalink
Browse files
IGNITE-16999 Sql. Refactor IgniteBuiltInMethod and IgniteMethod class…
…es - Fixes #811.

Signed-off-by: zstan <stanilovsky@gmail.com>
  • Loading branch information
zstan committed May 18, 2022
1 parent c508162 commit 5bb2548cbb4354996a8cd5102000da0c607a905d
Showing 6 changed files with 35 additions and 56 deletions.

This file was deleted.

@@ -21,6 +21,7 @@
import java.math.BigInteger;
import java.math.RoundingMode;
import org.apache.calcite.DataContext;
import org.apache.calcite.avatica.util.ByteString;
import org.apache.calcite.config.CalciteConnectionConfig;
import org.apache.calcite.linq4j.AbstractEnumerable;
import org.apache.calcite.linq4j.Enumerable;
@@ -35,6 +36,7 @@
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.type.SqlTypeName;
import org.apache.ignite.internal.sql.engine.type.IgniteTypeSystem;
import org.apache.ignite.internal.sql.engine.util.Commons;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
@@ -63,6 +65,11 @@ public static String toString(BigDecimal x) {
return x == null ? null : x.toPlainString();
}

/** CAST(VARBINARY AS VARCHAR). */
public static String toString(ByteString b) {
return b == null ? null : new String(b.getBytes(), Commons.typeFactory().getDefaultCharset());
}

private static BigDecimal setScale(int precision, int scale, BigDecimal decimal) {
return precision == IgniteTypeSystem.INSTANCE.getDefaultPrecision(SqlTypeName.DECIMAL)
? decimal : decimal.setScale(scale, RoundingMode.HALF_UP);
@@ -146,6 +153,11 @@ public static BigDecimal toBigDecimal(Object o, int precision, int scale) {
: toBigDecimal(o.toString(), precision, scale);
}

/** CAST(VARCHAR AS VARBINARY). */
public static ByteString toByteString(String s) {
return s == null ? null : new ByteString(s.getBytes(Commons.typeFactory().getDefaultCharset()));
}

/**
* Dummy table to implement the SYSTEM_RANGE function.
*/
@@ -74,6 +74,7 @@
import org.apache.calcite.util.BuiltInMethod;
import org.apache.calcite.util.ControlFlowException;
import org.apache.calcite.util.Pair;
import org.apache.ignite.internal.sql.engine.util.IgniteMethod;

/**
* Translates {@link RexNode REX expressions} to {@link Expression linq4j expressions}.
@@ -534,8 +535,8 @@ Expression translateCast(
SqlIntervalQualifier intervalQualifier = targetType.getIntervalQualifier();

Method method = intervalQualifier.isYearMonth()
? IgniteBuiltInMethod.PARSE_INTERVAL_YEAR_MONTH.method
: IgniteBuiltInMethod.PARSE_INTERVAL_DAY_TIME.method;
? IgniteMethod.PARSE_INTERVAL_YEAR_MONTH.method()
: IgniteMethod.PARSE_INTERVAL_DAY_TIME.method();

convert = Expressions.call(
method,
@@ -220,13 +220,11 @@ private void flush() {

assert currentReq != null;

boolean hasMoreRow = waiting != -1 || lastRow != null;
taskScheduled.set(false);

currentReq.fut.complete(new BatchedResult<>(currentReq.buff, waiting != -1 || lastRow != null));

if (pendingRequests.isEmpty()) {
taskScheduled.set(false);
}
boolean hasMoreRow = waiting != -1 || lastRow != null;

if (hasMoreRow) {
scheduleTask();
@@ -18,7 +18,10 @@
package org.apache.ignite.internal.sql.engine.util;

import java.lang.reflect.Method;
import org.apache.calcite.avatica.util.ByteString;
import org.apache.calcite.linq4j.tree.Types;
import org.apache.calcite.sql.SqlIntervalQualifier;
import org.apache.calcite.sql.parser.SqlParserUtil;
import org.apache.ignite.internal.sql.engine.exec.ExecutionContext;
import org.apache.ignite.internal.sql.engine.exec.RowHandler;
import org.apache.ignite.internal.sql.engine.exec.exp.BiScalar;
@@ -58,7 +61,19 @@ public enum IgniteMethod {
SYSTEM_RANGE3(IgniteSqlFunctions.class, "systemRange", Object.class, Object.class, Object.class),

/** See {@link FragmentMappingMetadata#fragmentMapping(MappingQueryContext)}. */
FRAGMENT_MAPPING(FragmentMappingMetadata.class, "fragmentMapping", MappingQueryContext.class);
FRAGMENT_MAPPING(FragmentMappingMetadata.class, "fragmentMapping", MappingQueryContext.class),

/** See {@link SqlParserUtil#intervalToMonths(String, SqlIntervalQualifier)}. */
PARSE_INTERVAL_YEAR_MONTH(SqlParserUtil.class, "intervalToMonths", String.class, SqlIntervalQualifier.class),

/** See {@link SqlParserUtil#intervalToMillis(String, SqlIntervalQualifier)}. */
PARSE_INTERVAL_DAY_TIME(SqlParserUtil.class, "intervalToMillis", String.class, SqlIntervalQualifier.class),

/** See {@link IgniteSqlFunctions#toString(ByteString)}. */
BYTESTRING_TO_STRING(IgniteSqlFunctions.class, "toString", ByteString.class),

/** See {@link IgniteSqlFunctions#toByteString(String)}. */
STRING_TO_BYTESTRING(IgniteSqlFunctions.class, "toByteString", String.class);

private final Method method;

@@ -30,7 +30,7 @@
public class IgniteSqlFunctionsTest {
@Test
public void testBigDecimalToString() {
assertNull(IgniteSqlFunctions.toString(null));
assertNull(IgniteSqlFunctions.toString((BigDecimal) null));

assertEquals(
"10",
@@ -110,7 +110,7 @@ public void testObjectToDecimal() {

assertEquals(
new BigDecimal(10),
IgniteSqlFunctions.toBigDecimal(new Byte("10"), 10, 0)
IgniteSqlFunctions.toBigDecimal(Byte.valueOf("10"), 10, 0)
);

assertEquals(

0 comments on commit 5bb2548

Please sign in to comment.