• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java NlsString类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.calcite.util.NlsString的典型用法代码示例。如果您正苦于以下问题:Java NlsString类的具体用法?Java NlsString怎么用?Java NlsString使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



NlsString类属于org.apache.calcite.util包,在下文中一共展示了NlsString类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: convertCall

import org.apache.calcite.util.NlsString; //导入依赖的package包/类
@Override
public RexNode convertCall(SqlRexContext cx, SqlCall call) {
  final RexBuilder rexBuilder = cx.getRexBuilder();

  final SqlLiteral literal = (SqlLiteral) call.getOperandList().get(0);
  final String value = ((NlsString)literal.getValue()).getValue();
  TimeUnitRange range = VALID_PERIODS.get(value.toLowerCase());
  Preconditions.checkNotNull(range, "Unhandle range type: %s.", value);
  List<RexNode> exprs = new ArrayList<>();

  exprs.add(rexBuilder.makeFlag(range));
  exprs.add(cx.convertExpression(call.getOperandList().get(1)));

  RelDataTypeFactory typeFactory = cx.getTypeFactory();
  final RelDataType returnType
      = typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.BIGINT), exprs.get(1).getType().isNullable());
  return rexBuilder.makeCall(returnType, SqlStdOperatorTable.EXTRACT, exprs);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:19,代码来源:SqlDatePartOperator.java


示例2: visitLiteral

import org.apache.calcite.util.NlsString; //导入依赖的package包/类
@Override
public TupleFilter visitLiteral(RexLiteral literal) {
    String strValue = null;
    Object literalValue = literal.getValue();
    if (literalValue instanceof NlsString) {
        strValue = ((NlsString) literalValue).getValue();
    } else if (literalValue instanceof GregorianCalendar) {
        GregorianCalendar g = (GregorianCalendar) literalValue;
        //strValue = "" + g.get(Calendar.YEAR) + "-" + normToTwoDigits(g.get(Calendar.MONTH) + 1) + "-" + normToTwoDigits(g.get(Calendar.DAY_OF_MONTH));
        strValue = Long.toString(g.getTimeInMillis());
    } else if (literalValue instanceof TimeUnitRange) {
        // Extract(x from y) in where clause
        strValue = ((TimeUnitRange) literalValue).name();
    } else if (literalValue == null) {
        strValue = null;
    } else {
        strValue = literalValue.toString();
    }
    TupleFilter filter = new ConstantTupleFilter(strValue);
    return filter;
}
 
开发者ID:apache,项目名称:kylin,代码行数:22,代码来源:OLAPFilterRel.java


示例3: createNlsStringType

import org.apache.calcite.util.NlsString; //导入依赖的package包/类
/**
 * Creates the type of an {@link org.apache.calcite.util.NlsString}.
 *
 * <p>The type inherits the The NlsString's {@link Charset} and
 * {@link SqlCollation}, if they are set, otherwise it gets the system
 * defaults.
 *
 * @param typeFactory Type factory
 * @param str         String
 * @return Type, including collation and charset
 */
public static RelDataType createNlsStringType(
    RelDataTypeFactory typeFactory,
    NlsString str) {
  Charset charset = str.getCharset();
  if (null == charset) {
    charset = typeFactory.getDefaultCharset();
  }
  SqlCollation collation = str.getCollation();
  if (null == collation) {
    collation = SqlCollation.COERCIBLE;
  }
  RelDataType type =
      typeFactory.createSqlType(
          SqlTypeName.CHAR,
          str.getValue().length());
  type =
      typeFactory.createTypeWithCharsetAndCollation(
          type,
          charset,
          collation);
  return type;
}
 
开发者ID:apache,项目名称:calcite,代码行数:34,代码来源:SqlUtil.java


示例4: inferAlias

import org.apache.calcite.util.NlsString; //导入依赖的package包/类
/** Infers the alias of an expression.
 *
 * <p>If the expression was created by {@link #alias}, replaces the expression
 * in the project list.
 */
private String inferAlias(List<RexNode> exprList, RexNode expr) {
  switch (expr.getKind()) {
  case INPUT_REF:
    final RexInputRef ref = (RexInputRef) expr;
    return stack.peek().fields.get(ref.getIndex()).getValue().getName();
  case CAST:
    return inferAlias(exprList, ((RexCall) expr).getOperands().get(0));
  case AS:
    final RexCall call = (RexCall) expr;
    for (;;) {
      final int i = exprList.indexOf(expr);
      if (i < 0) {
        break;
      }
      exprList.set(i, call.getOperands().get(0));
    }
    return ((NlsString) ((RexLiteral) call.getOperands().get(1)).getValue())
        .getValue();
  default:
    return null;
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:28,代码来源:RelBuilder.java


示例5: RexBuilder

import org.apache.calcite.util.NlsString; //导入依赖的package包/类
/**
 * Creates a RexBuilder.
 *
 * @param typeFactory Type factory
 */
public RexBuilder(RelDataTypeFactory typeFactory) {
  this.typeFactory = typeFactory;
  this.booleanTrue =
      makeLiteral(
          Boolean.TRUE,
          typeFactory.createSqlType(SqlTypeName.BOOLEAN),
          SqlTypeName.BOOLEAN);
  this.booleanFalse =
      makeLiteral(
          Boolean.FALSE,
          typeFactory.createSqlType(SqlTypeName.BOOLEAN),
          SqlTypeName.BOOLEAN);
  this.charEmpty =
      makeLiteral(
          new NlsString("", null, null),
          typeFactory.createSqlType(SqlTypeName.CHAR, 0),
          SqlTypeName.CHAR);
  this.constantNull =
      makeLiteral(
          null,
          typeFactory.createSqlType(SqlTypeName.NULL),
          SqlTypeName.NULL);
}
 
开发者ID:apache,项目名称:calcite,代码行数:29,代码来源:RexBuilder.java


示例6: createOptionValue

import org.apache.calcite.util.NlsString; //导入依赖的package包/类
private static OptionValue createOptionValue(final String name, final OptionValue.OptionType type,
                                             final SqlLiteral literal) {
  final Object object = literal.getValue();
  final SqlTypeName typeName = literal.getTypeName();
  switch (typeName) {
  case DECIMAL: {
    final BigDecimal bigDecimal = (BigDecimal) object;
    if (bigDecimal.scale() == 0) {
      return OptionValue.createLong(type, name, bigDecimal.longValue());
    } else {
      return OptionValue.createDouble(type, name, bigDecimal.doubleValue());
    }
  }

  case DOUBLE:
  case FLOAT:
    return OptionValue.createDouble(type, name, ((BigDecimal) object).doubleValue());

  case SMALLINT:
  case TINYINT:
  case BIGINT:
  case INTEGER:
    return OptionValue.createLong(type, name, ((BigDecimal) object).longValue());

  case VARBINARY:
  case VARCHAR:
  case CHAR:
    return OptionValue.createString(type, name, ((NlsString) object).getValue());

  case BOOLEAN:
    return OptionValue.createBoolean(type, name, (Boolean) object);

  default:
    throw UserException.validationError()
      .message("Drill doesn't support assigning literals of type %s in SET statements.", typeName)
      .build(logger);
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:39,代码来源:SetOptionHandler.java


示例7: checkSingleOperandType

import org.apache.calcite.util.NlsString; //导入依赖的package包/类
@Override
public boolean checkSingleOperandType(SqlCallBinding callBinding, SqlNode node,
    int iFormalOperand, boolean throwOnFailure) {

  // check that the input is a literal.
  if(!super.checkSingleOperandType(callBinding, node, iFormalOperand, throwOnFailure)) {
    return false;
  }

  final RelDataType type = callBinding.getValidator().deriveType(callBinding.getScope(), node);
  final SqlTypeName typeName = type.getSqlTypeName();

  // Pass type checking for operators if it's of type 'ANY'.
  if (typeName.getFamily() == SqlTypeFamily.ANY) {
    return true;
  }

  if(!(typeName == SqlTypeName.CHAR || typeName == SqlTypeName.VARCHAR)) {
    if(throwOnFailure) {
      throw callBinding.newValidationSignatureError();
    }
    return false;
  }

  final SqlLiteral literal = (SqlLiteral) node;
  final String value = ((NlsString)literal.getValue()).getValue();
  if(validStrings.contains(value.toLowerCase())) {
    return true;
  }

  if(throwOnFailure) {
    throw callBinding.newValidationSignatureError();
    //throw new SqlValidatorException(String.format("DATE_PART function only accepts the following values for a date type: %s.", Joiner.on(", ").join(validStrings)), null);
  }

  return false;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:38,代码来源:SqlDatePartOperator.java


示例8: createStorageOptionsMap

import org.apache.calcite.util.NlsString; //导入依赖的package包/类
/**
 * Helper method to create map of key, value pairs, the value is a Java type object.
 * @param args
 * @return
 */
protected static Map<String, Object> createStorageOptionsMap(SqlHandlerConfig config, final SqlNodeList args) {
  if (args == null || args.size() == 0) {
    return null;
  }

  final ImmutableMap.Builder<String, Object> storageOptions = ImmutableMap.builder();
  for (SqlNode operand : args) {
    if (operand.getKind() != SqlKind.ARGUMENT_ASSIGNMENT) {
      throw UserException.unsupportedError()
          .message("Unsupported argument type. Only assignment arguments (param => value) are supported.")
          .build(logger);
    }
    final List<SqlNode> operandList = ((SqlCall) operand).getOperandList();

    final String name = ((SqlIdentifier) operandList.get(1)).getSimple();
    SqlNode literal = operandList.get(0);
    if (!(literal instanceof SqlLiteral)) {
      throw UserException.unsupportedError()
          .message("Only literals are accepted for storage option values")
          .build(logger);
    }

    Object value = ((SqlLiteral)literal).getValue();
    if (value instanceof NlsString) {
      value = ((NlsString)value).getValue();
    }
    storageOptions.put(name, value);
  }

  return storageOptions.build();
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:37,代码来源:CreateTableHandler.java


示例9: createOptionValue

import org.apache.calcite.util.NlsString; //导入依赖的package包/类
private static OptionValue createOptionValue(final String name, final OptionValue.OptionType type,
                                             final SqlLiteral literal) {
  final Object object = literal.getValue();
  final SqlTypeName typeName = literal.getTypeName();
  switch (typeName) {
  case DECIMAL: {
    final BigDecimal bigDecimal = (BigDecimal) object;
    if (bigDecimal.scale() == 0) {
      return OptionValue.createLong(type, name, bigDecimal.longValue());
    } else {
      return OptionValue.createDouble(type, name, bigDecimal.doubleValue());
    }
  }

  case DOUBLE:
  case FLOAT:
    return OptionValue.createDouble(type, name, ((BigDecimal) object).doubleValue());

  case SMALLINT:
  case TINYINT:
  case BIGINT:
  case INTEGER:
    return OptionValue.createLong(type, name, ((BigDecimal) object).longValue());

  case VARBINARY:
  case VARCHAR:
  case CHAR:
    return OptionValue.createString(type, name, ((NlsString) object).getValue());

  case BOOLEAN:
    return OptionValue.createBoolean(type, name, (Boolean) object);

  default:
    throw UserException.validationError()
      .message("Dremio doesn't support assigning literals of type %s in SET statements.", typeName)
      .build(logger);
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:39,代码来源:SetOptionHandler.java


示例10: autoCastField

import org.apache.calcite.util.NlsString; //导入依赖的package包/类
public static Object autoCastField(int fieldType, Object rawObj) {
  if (rawObj == null) {
    return null;
  }

  SqlTypeName columnType = CalciteUtils.toCalciteType(fieldType);
  // auto-casting for numberics
  if ((rawObj instanceof String && SqlTypeName.NUMERIC_TYPES.contains(columnType))
      || (rawObj instanceof BigDecimal && columnType != SqlTypeName.DECIMAL)) {
    String raw = rawObj.toString();
    switch (columnType) {
      case TINYINT:
        return Byte.valueOf(raw);
      case SMALLINT:
        return Short.valueOf(raw);
      case INTEGER:
        return Integer.valueOf(raw);
      case BIGINT:
        return Long.valueOf(raw);
      case FLOAT:
        return Float.valueOf(raw);
      case DOUBLE:
        return Double.valueOf(raw);
      default:
        throw new UnsupportedOperationException(
            String.format("Column type %s is not supported yet!", columnType));
    }
  } else if (SqlTypeName.CHAR_TYPES.contains(columnType)) {
    // convert NlsString to String
    if (rawObj instanceof NlsString) {
      return ((NlsString) rawObj).getValue();
    } else {
      return rawObj;
    }
  } else {
    return rawObj;
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:39,代码来源:BeamTableUtils.java


示例11: sqlLiteralToObject

import org.apache.calcite.util.NlsString; //导入依赖的package包/类
private static Object sqlLiteralToObject(final SqlLiteral literal) {
  final Object object = literal.getValue();
  final SqlTypeName typeName = literal.getTypeName();
  switch (typeName) {
  case DECIMAL: {
    final BigDecimal bigDecimal = (BigDecimal) object;
    if (bigDecimal.scale() == 0) {
      return bigDecimal.longValue();
    } else {
      return bigDecimal.doubleValue();
    }
  }

  case DOUBLE:
  case FLOAT:
    return ((BigDecimal) object).doubleValue();

  case SMALLINT:
  case TINYINT:
  case BIGINT:
  case INTEGER:
    return ((BigDecimal) object).longValue();

  case VARBINARY:
  case VARCHAR:
  case CHAR:
    return ((NlsString) object).getValue().toString();

  case BOOLEAN:
    return object;

  default:
    throw UserException.validationError()
      .message("Drill doesn't support assigning literals of type %s in SET statements.", typeName)
      .build(logger);
  }
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:38,代码来源:SetOptionHandler.java


示例12: getOperandValue

import org.apache.calcite.util.NlsString; //导入依赖的package包/类
protected static Object getOperandValue(SqlNode node, List<Object> parameterValues) {
    if (SqlKind.DYNAMIC_PARAM == node.getKind()) {
        if (parameterValues == null || parameterValues.isEmpty()) {
            throw new IllegalArgumentException("Parameter values: " + parameterValues);
        }
        return parameterValues.get(((SqlDynamicParam) node).getIndex());
    }
    if (SqlKind.LITERAL != node.getKind()) {
        if (SqlKind.IDENTIFIER == node.getKind()) {
            SqlIdentifier identifier = (SqlIdentifier) node;
            if (identifier.isSimple() && "nan".equals(identifier.getSimple())) {
                return Double.NaN;
            }
        }
        throw new IllegalArgumentException("Illegal operand kind: " + node.getKind());
    }
    SqlLiteral literal = (SqlLiteral) node;
    switch (literal.getTypeName().getFamily()) {
        case BOOLEAN:
            return literal.booleanValue();
        case CHARACTER:
            return ((NlsString) literal.getValue()).getValue();
        case NULL:
            return null;
        case NUMERIC:
            return literal.getValue();
        default: {
            throw new IllegalArgumentException("Unknown operand type: " + literal.getTypeName());
        }
    }
}
 
开发者ID:axibase,项目名称:atsd-jdbc,代码行数:32,代码来源:AtsdSqlConverter.java


示例13: toString

import org.apache.calcite.util.NlsString; //导入依赖的package包/类
private String toString(boolean like, RexLiteral literal) {
  String value = null;
  SqlTypeName litSqlType = literal.getTypeName();
  if (SqlTypeName.NUMERIC_TYPES.contains(litSqlType)) {
    value = literal.getValue().toString();
  } else if (litSqlType == SqlTypeName.CHAR) {
    value = ((NlsString) literal.getValue()).getValue();
    if (like) {
      value = value.replaceAll("%", "*");
    }
    value = searchEscape(value);
  }
  return value;
}
 
开发者ID:apache,项目名称:calcite,代码行数:15,代码来源:SplunkPushDownRule.java


示例14: toValue

import org.apache.calcite.util.NlsString; //导入依赖的package包/类
/**
 * For calc program builder - value may be different than {@link #unparse}
 * Typical values:
 *
 * <ul>
 * <li>Hello, world!</li>
 * <li>12.34</li>
 * <li>{null}</li>
 * <li>1969-04-29</li>
 * </ul>
 *
 * @return string representation of the value
 */
public String toValue() {
  if (value == null) {
    return null;
  }
  switch (typeName) {
  case CHAR:

    // We want 'It''s superman!', not _ISO-8859-1'It''s superman!'
    return ((NlsString) value).getValue();
  default:
    return value.toString();
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:27,代码来源:SqlLiteral.java


示例15: zeroValue

import org.apache.calcite.util.NlsString; //导入依赖的package包/类
private static Comparable zeroValue(RelDataType type) {
  switch (type.getSqlTypeName()) {
  case CHAR:
    return new NlsString(Spaces.of(type.getPrecision()), null, null);
  case VARCHAR:
    return new NlsString("", null, null);
  case BINARY:
    return new ByteString(new byte[type.getPrecision()]);
  case VARBINARY:
    return ByteString.EMPTY;
  case TINYINT:
  case SMALLINT:
  case INTEGER:
  case BIGINT:
  case DECIMAL:
  case FLOAT:
  case REAL:
  case DOUBLE:
    return BigDecimal.ZERO;
  case BOOLEAN:
    return false;
  case TIME:
  case DATE:
  case TIMESTAMP:
    return DateTimeUtils.ZERO_CALENDAR;
  case TIME_WITH_LOCAL_TIME_ZONE:
    return new TimeString(0, 0, 0);
  case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
    return new TimestampString(0, 0, 0, 0, 0, 0);
  default:
    throw Util.unexpected(type.getSqlTypeName());
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:34,代码来源:RexBuilder.java


示例16: padRight

import org.apache.calcite.util.NlsString; //导入依赖的package包/类
/** Returns an {@link NlsString} with spaces to make it at least a given
 * length. */
private static NlsString padRight(NlsString s, int length) {
  if (s.getValue().length() >= length) {
    return s;
  }
  return s.copy(padRight(s.getValue(), length));
}
 
开发者ID:apache,项目名称:calcite,代码行数:9,代码来源:RexBuilder.java


示例17: validConstant

import org.apache.calcite.util.NlsString; //导入依赖的package包/类
/** Returns whether a value is valid as a constant value, using the same
 * criteria as {@link #valueMatchesType}. */
public static boolean validConstant(Object o, Litmus litmus) {
  if (o == null
      || o instanceof BigDecimal
      || o instanceof NlsString
      || o instanceof ByteString) {
    return litmus.succeed();
  } else if (o instanceof List) {
    List list = (List) o;
    for (Object o1 : list) {
      if (!validConstant(o1, litmus)) {
        return litmus.fail("not a constant: {}", o1);
      }
    }
    return litmus.succeed();
  } else if (o instanceof Map) {
    @SuppressWarnings("unchecked") final Map<Object, Object> map = (Map) o;
    for (Map.Entry entry : map.entrySet()) {
      if (!validConstant(entry.getKey(), litmus)) {
        return litmus.fail("not a constant: {}", entry.getKey());
      }
      if (!validConstant(entry.getValue(), litmus)) {
        return litmus.fail("not a constant: {}", entry.getValue());
      }
    }
    return litmus.succeed();
  } else {
    return litmus.fail("not a constant: {}", o);
  }
}
 
开发者ID:apache,项目名称:calcite,代码行数:32,代码来源:RexLiteral.java


示例18: testSubstring

import org.apache.calcite.util.NlsString; //导入依赖的package包/类
@Test public void testSubstring() throws Exception {
  check(new Action() {
    public void check(RexBuilder rexBuilder, RexExecutorImpl executor) {
      final List<RexNode> reducedValues = new ArrayList<>();
      final RexLiteral hello =
          rexBuilder.makeCharLiteral(
              new NlsString("Hello world!", null, null));
      final RexNode plus =
          rexBuilder.makeCall(SqlStdOperatorTable.PLUS,
              rexBuilder.makeExactLiteral(BigDecimal.ONE),
              rexBuilder.makeExactLiteral(BigDecimal.ONE));
      RexLiteral four = rexBuilder.makeExactLiteral(BigDecimal.valueOf(4));
      final RexNode substring =
          rexBuilder.makeCall(SqlStdOperatorTable.SUBSTRING,
              hello, plus, four);
      executor.reduce(rexBuilder, ImmutableList.of(substring, plus),
          reducedValues);
      assertThat(reducedValues.size(), equalTo(2));
      assertThat(reducedValues.get(0), instanceOf(RexLiteral.class));
      assertThat(((RexLiteral) reducedValues.get(0)).getValue2(),
          equalTo((Object) "ello")); // substring('Hello world!, 2, 4)
      assertThat(reducedValues.get(1), instanceOf(RexLiteral.class));
      assertThat(((RexLiteral) reducedValues.get(1)).getValue2(),
          equalTo((Object) 2L));
    }
  });
}
 
开发者ID:apache,项目名称:calcite,代码行数:28,代码来源:RexExecutorTest.java


示例19: inferReturnType

import org.apache.calcite.util.NlsString; //导入依赖的package包/类
@Override
public RelDataType inferReturnType(SqlOperatorBinding opBinding) {
  final RelDataTypeFactory factory = opBinding.getTypeFactory();
  SqlTypeName typeToCastTo = null;
  if (opBinding instanceof SqlCallBinding) {
    SqlCallBinding sqlCallBinding = (SqlCallBinding) opBinding;
    if (sqlCallBinding.operand(1).getKind() == SqlKind.LITERAL) {
      String type = null;
      try {
        SqlLiteral sqlLiteral = (SqlLiteral) sqlCallBinding.operand(1);
        type = ((NlsString) sqlLiteral.getValue()).getValue();
        switch(type) {
          case "JSON":
            typeToCastTo = SqlTypeName.ANY;
            break;
          case "UTF8":
          case "UTF16":
            typeToCastTo = SqlTypeName.VARCHAR;
            break;
          case "BOOLEAN_BYTE":
            typeToCastTo = SqlTypeName.BOOLEAN;
            break;
          case "TINYINT_BE":
          case "TINYINT":
            typeToCastTo = SqlTypeName.TINYINT;
            break;
          case "SMALLINT_BE":
          case "SMALLINT":
            typeToCastTo = SqlTypeName.SMALLINT;
            break;
          case "INT_BE":
          case "INT":
          case "INT_HADOOPV":
            typeToCastTo = SqlTypeName.INTEGER;
            break;
          case "BIGINT_BE":
          case "BIGINT":
          case "BIGINT_HADOOPV":
            typeToCastTo = SqlTypeName.BIGINT;
            break;
          case "FLOAT":
            typeToCastTo = SqlTypeName.FLOAT;
            break;
          case "DOUBLE":
            typeToCastTo = SqlTypeName.DOUBLE;
            break;
          case "DATE_EPOCH_BE":
          case "DATE_EPOCH":
            typeToCastTo = SqlTypeName.DATE;
            break;
          case "TIME_EPOCH_BE":
          case "TIME_EPOCH":
            typeToCastTo = SqlTypeName.TIME;
            break;
          case "TIMESTAMP_EPOCH":
          case "TIMESTAMP_IMPALA":
            typeToCastTo = SqlTypeName.TIMESTAMP;
            break;
          default:
            typeToCastTo = SqlTypeName.ANY;
            break;
        }
      } catch (final ClassCastException e) {
        logger.debug("Failed to parse string for convert_from()");
      }
    }
  }

  if (typeToCastTo == null) {
    typeToCastTo = SqlTypeName.ANY;
  }
  return factory.createTypeWithNullability(
      factory.createSqlType(typeToCastTo),
      true);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:76,代码来源:TypeInferenceUtils.java


示例20: toSplitsSearchQuery

import org.apache.calcite.util.NlsString; //导入依赖的package包/类
public static SearchQuery toSplitsSearchQuery(List<FilterProperties> filters, Field field) {
  Preconditions.checkNotNull(field);

  final CompleteType ct = CompleteType.fromField(field);

  final FieldType fieldType = getFieldType(ct);
  final String columnKey = DatasetSplitConverter.buildColumnKey(fieldType, field.getName());
  final SearchQuery partitionColumnNotDefinedQuery = SearchQueryUtils.newDoesNotExistQuery(columnKey);
  final List<SearchQuery> filterQueries = Lists.newArrayList();

  for (FilterProperties filter: filters) {
    final RexLiteral literal = filter.getLiteral();
    SearchQuery matchingSplitsQuery = null;
    final RangeQueryInput rangeQueryInput;
    switch (ct.toMinorType()) {
      case BIGINT:

        rangeQueryInput = new RangeQueryInput(
          ((BigDecimal) literal.getValue()).setScale(0, BigDecimal.ROUND_HALF_UP).longValue(), filter.getKind());
        matchingSplitsQuery = SearchQueryUtils.newRangeLong(columnKey, (Long) rangeQueryInput.min, (Long) rangeQueryInput.max, rangeQueryInput.includeMin, rangeQueryInput.includeMax);
        break;

      case DATE:
      case TIME:
        rangeQueryInput = new RangeQueryInput((int) ((GregorianCalendar) literal.getValue()).getTimeInMillis(), filter.getKind());
        matchingSplitsQuery = SearchQueryUtils.newRangeInt(columnKey, (Integer) rangeQueryInput.min, (Integer) rangeQueryInput.max, rangeQueryInput.includeMin, rangeQueryInput.includeMax);
        break;

      case VARCHAR:
        if (literal.getValue() instanceof  NlsString) {
          rangeQueryInput = new RangeQueryInput(((NlsString) literal.getValue()).getValue(), filter.getKind());
        } else {
          rangeQueryInput = new RangeQueryInput((literal.getValue3().toString()), filter.getKind());
        }
        matchingSplitsQuery = SearchQueryUtils.newRangeTerm(columnKey, (String) rangeQueryInput.min, (String) rangeQueryInput.max, rangeQueryInput.includeMin, rangeQueryInput.includeMax);
        break;

      case FLOAT4:
        rangeQueryInput = new RangeQueryInput(((BigDecimal) literal.getValue()).floatValue(), filter.getKind());
        matchingSplitsQuery = SearchQueryUtils.newRangeFloat(columnKey, (Float) rangeQueryInput.min, (Float) rangeQueryInput.max, rangeQueryInput.includeMin, rangeQueryInput.includeMax);
        break;

      case FLOAT8:
        rangeQueryInput = new RangeQueryInput(((BigDecimal) literal.getValue()).doubleValue(), filter.getKind());
        matchingSplitsQuery = SearchQueryUtils.newRangeDouble(columnKey, (Double) rangeQueryInput.min, (Double) rangeQueryInput.max, rangeQueryInput.includeMin, rangeQueryInput.includeMax);
        break;

      case INT:
        rangeQueryInput = new RangeQueryInput(((BigDecimal) literal.getValue()).setScale(0, BigDecimal.ROUND_HALF_UP).intValue(), filter.getKind());
        matchingSplitsQuery = SearchQueryUtils.newRangeInt(columnKey, (Integer) rangeQueryInput.min, (Integer) rangeQueryInput.max, rangeQueryInput.includeMin, rangeQueryInput.includeMax);
        break;

      case TIMESTAMP:
        rangeQueryInput = new RangeQueryInput(((GregorianCalendar) literal.getValue()).getTimeInMillis(), filter.getKind());
        matchingSplitsQuery = SearchQueryUtils.newRangeLong(columnKey, (Long) rangeQueryInput.min, (Long) rangeQueryInput.max, rangeQueryInput.includeMin, rangeQueryInput.includeMax);
        break;

      default:
        throw new UnsupportedOperationException("type not supported " + ct.toMinorType());
    }
    if (matchingSplitsQuery != null) {
      filterQueries.add(matchingSplitsQuery);
    }
  }

  return SearchQueryUtils.or(SearchQueryUtils.and(filterQueries), partitionColumnNotDefinedQuery);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:68,代码来源:MetadataUtils.java



注:本文中的org.apache.calcite.util.NlsString类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java LongMonitoredAttributeBase类代码示例发布时间:2022-05-22
下一篇:
Java IOSApplication类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap