Exemplo n.º 1
0
 public static void initBuiltins(Db db) {
   db.addBuiltin(
       ScalarFunction.createBuiltinOperator(
           Operator.AND.name(),
           "CompoundPredicate",
           "AndComputeFn",
           Lists.newArrayList(ColumnType.BOOLEAN, ColumnType.BOOLEAN),
           ColumnType.BOOLEAN));
   db.addBuiltin(
       ScalarFunction.createBuiltinOperator(
           Operator.OR.name(),
           "CompoundPredicate",
           "OrComputeFn",
           Lists.newArrayList(ColumnType.BOOLEAN, ColumnType.BOOLEAN),
           ColumnType.BOOLEAN));
   db.addBuiltin(
       ScalarFunction.createBuiltinOperator(
           Operator.NOT.name(),
           "CompoundPredicate",
           "NotComputeFn",
           Lists.newArrayList(ColumnType.BOOLEAN),
           ColumnType.BOOLEAN));
 }
Exemplo n.º 2
0
 public static void initBuiltins(Db db) {
   for (Type fromType : Type.getSupportedTypes()) {
     if (fromType.isNull()) continue;
     for (Type toType : Type.getSupportedTypes()) {
       if (toType.isNull()) continue;
       // Disable casting from string to boolean
       if (fromType.isStringType() && toType.isBoolean()) continue;
       // Disable casting from boolean/timestamp to decimal
       if ((fromType.isBoolean() || fromType.isDateType()) && toType.isDecimal()) {
         continue;
       }
       if (fromType.getPrimitiveType() == PrimitiveType.STRING
           && toType.getPrimitiveType() == PrimitiveType.CHAR) {
         // Allow casting from String to Char(N)
         String beSymbol = "impala::CastFunctions::CastToChar";
         db.addBuiltin(
             ScalarFunction.createBuiltin(
                 getFnName(ScalarType.CHAR),
                 Lists.newArrayList((Type) ScalarType.STRING),
                 false,
                 ScalarType.CHAR,
                 beSymbol,
                 null,
                 null,
                 true));
         continue;
       }
       if (fromType.getPrimitiveType() == PrimitiveType.CHAR
           && toType.getPrimitiveType() == PrimitiveType.CHAR) {
         // Allow casting from CHAR(N) to Char(N)
         String beSymbol = "impala::CastFunctions::CastToChar";
         db.addBuiltin(
             ScalarFunction.createBuiltin(
                 getFnName(ScalarType.CHAR),
                 Lists.newArrayList((Type) ScalarType.createCharType(-1)),
                 false,
                 ScalarType.CHAR,
                 beSymbol,
                 null,
                 null,
                 true));
         continue;
       }
       if (fromType.getPrimitiveType() == PrimitiveType.VARCHAR
           && toType.getPrimitiveType() == PrimitiveType.VARCHAR) {
         // Allow casting from VARCHAR(N) to VARCHAR(M)
         String beSymbol = "impala::CastFunctions::CastToStringVal";
         db.addBuiltin(
             ScalarFunction.createBuiltin(
                 getFnName(ScalarType.VARCHAR),
                 Lists.newArrayList((Type) ScalarType.VARCHAR),
                 false,
                 ScalarType.VARCHAR,
                 beSymbol,
                 null,
                 null,
                 true));
         continue;
       }
       if (fromType.getPrimitiveType() == PrimitiveType.VARCHAR
           && toType.getPrimitiveType() == PrimitiveType.CHAR) {
         // Allow casting from VARCHAR(N) to CHAR(M)
         String beSymbol = "impala::CastFunctions::CastToChar";
         db.addBuiltin(
             ScalarFunction.createBuiltin(
                 getFnName(ScalarType.CHAR),
                 Lists.newArrayList((Type) ScalarType.VARCHAR),
                 false,
                 ScalarType.CHAR,
                 beSymbol,
                 null,
                 null,
                 true));
         continue;
       }
       if (fromType.getPrimitiveType() == PrimitiveType.CHAR
           && toType.getPrimitiveType() == PrimitiveType.VARCHAR) {
         // Allow casting from CHAR(N) to VARCHAR(M)
         String beSymbol = "impala::CastFunctions::CastToStringVal";
         db.addBuiltin(
             ScalarFunction.createBuiltin(
                 getFnName(ScalarType.VARCHAR),
                 Lists.newArrayList((Type) ScalarType.CHAR),
                 false,
                 ScalarType.VARCHAR,
                 beSymbol,
                 null,
                 null,
                 true));
         continue;
       }
       // Disable no-op casts
       if (fromType.equals(toType) && !fromType.isDecimal()) continue;
       String beClass =
           toType.isDecimal() || fromType.isDecimal() ? "DecimalOperators" : "CastFunctions";
       String beSymbol = "impala::" + beClass + "::CastTo" + Function.getUdfType(toType);
       db.addBuiltin(
           ScalarFunction.createBuiltin(
               getFnName(toType),
               Lists.newArrayList(fromType),
               false,
               toType,
               beSymbol,
               null,
               null,
               true));
     }
   }
 }