Exemplo n.º 1
0
  @Before
  public void setUp() throws Exception {
    tuple1 =
        new VTuple(
            new Datum[] {
              DatumFactory.createBool(true),
              DatumFactory.createBit((byte) 0x99),
              DatumFactory.createChar('9'),
              DatumFactory.createInt2((short) 17),
              DatumFactory.createInt4(59),
              DatumFactory.createInt8(23l),
              DatumFactory.createFloat4(77.9f),
              DatumFactory.createFloat8(271.9f),
              DatumFactory.createText("hyunsik"),
              DatumFactory.createBlob("hyunsik".getBytes()),
              DatumFactory.createInet4("192.168.0.1")
            });

    tuple2 =
        new VTuple(
            new Datum[] {
              DatumFactory.createBool(true),
              DatumFactory.createBit((byte) 0x99),
              DatumFactory.createChar('9'),
              DatumFactory.createInt2((short) 17),
              DatumFactory.createInt4(59),
              DatumFactory.createInt8(23l),
              DatumFactory.createFloat4(77.9f),
              DatumFactory.createFloat8(271.9f),
              DatumFactory.createText("hyunsik"),
              DatumFactory.createBlob("hyunsik".getBytes()),
              DatumFactory.createInet4("192.168.0.1")
            });
  }
Exemplo n.º 2
0
  static {
    schema.addColumn("col1", Type.BOOLEAN);
    schema.addColumn("col2", Type.CHAR, 7);
    schema.addColumn("col3", Type.INT2);
    schema.addColumn("col4", Type.INT4);
    schema.addColumn("col5", Type.INT8);
    schema.addColumn("col6", Type.FLOAT4);
    schema.addColumn("col7", Type.FLOAT8);
    schema.addColumn("col8", Type.TEXT);
    schema.addColumn("col9", Type.BLOB);
    schema.addColumn("col10", Type.INET4);

    baseTuple =
        new VTuple(
            new Datum[] {
              DatumFactory.createBool(true), // 0
              DatumFactory.createChar("hyunsik"), // 1
              DatumFactory.createInt2((short) 17), // 2
              DatumFactory.createInt4(59), // 3
              DatumFactory.createInt8(23l), // 4
              DatumFactory.createFloat4(77.9f), // 5
              DatumFactory.createFloat8(271.9d), // 6
              DatumFactory.createText("hyunsik"), // 7
              DatumFactory.createBlob("hyunsik".getBytes()), // 8
              DatumFactory.createInet4("192.168.0.1"), // 9
            });
  }
Exemplo n.º 3
0
  @Override
  public Datum eval(Tuple params) {
    if (params.isBlankOrNull(0)) {
      return NullDatum.get();
    }

    return DatumFactory.createFloat8(Math.asin(params.getFloat8(0)));
  }
Exemplo n.º 4
0
 public static Datum cast(Datum operandDatum, DataType target, @Nullable TimeZone tz) {
   switch (target.getType()) {
     case BOOLEAN:
       return DatumFactory.createBool(operandDatum.asBool());
     case CHAR:
       return DatumFactory.createChar(operandDatum.asChar());
     case INT1:
     case INT2:
       return DatumFactory.createInt2(operandDatum.asInt2());
     case INT4:
       return DatumFactory.createInt4(operandDatum.asInt4());
     case INT8:
       return DatumFactory.createInt8(operandDatum.asInt8());
     case FLOAT4:
       return DatumFactory.createFloat4(operandDatum.asFloat4());
     case FLOAT8:
       return DatumFactory.createFloat8(operandDatum.asFloat8());
     case VARCHAR:
     case TEXT:
       switch (operandDatum.type()) {
         case TIMESTAMP:
           {
             TimestampDatum timestampDatum = (TimestampDatum) operandDatum;
             if (tz != null) {
               return DatumFactory.createText(
                   TimestampDatum.asChars(operandDatum.asTimeMeta(), tz, false));
             } else {
               return DatumFactory.createText(timestampDatum.asChars());
             }
           }
         default:
           return DatumFactory.createText(operandDatum.asTextBytes());
       }
     case DATE:
       return DatumFactory.createDate(operandDatum);
     case TIME:
       return DatumFactory.createTime(operandDatum);
     case TIMESTAMP:
       return DatumFactory.createTimestamp(operandDatum, tz);
     case BLOB:
       return DatumFactory.createBlob(operandDatum.asByteArray());
     case INET4:
       return DatumFactory.createInet4(operandDatum.asByteArray());
     case ANY:
       return DatumFactory.createAny(operandDatum);
     default:
       throw new TajoRuntimeException(
           new InvalidValueForCastException(operandDatum.type(), target.getType()));
   }
 }
Exemplo n.º 5
0
 public Datum toDatum(int i) {
   if (keys[i] == null) {
     return NullDatum.get();
   }
   switch (keyTypes[i]) {
     case NULL_TYPE:
       return NullDatum.get();
     case BOOLEAN:
       return DatumFactory.createBool((Boolean) keys[i]);
     case BIT:
       return DatumFactory.createBit((Byte) keys[i]);
     case INT1:
     case INT2:
       return DatumFactory.createInt2((Short) keys[i]);
     case INT4:
       return DatumFactory.createInt4((Integer) keys[i]);
     case DATE:
       return DatumFactory.createDate((Integer) keys[i]);
     case INT8:
       return DatumFactory.createInt8((Long) keys[i]);
     case TIME:
       return DatumFactory.createTime((Long) keys[i]);
     case TIMESTAMP:
       return DatumFactory.createTimestamp((Long) keys[i]);
     case FLOAT4:
       return DatumFactory.createFloat4((Float) keys[i]);
     case FLOAT8:
       return DatumFactory.createFloat8((Double) keys[i]);
     case TEXT:
       return DatumFactory.createText((byte[]) keys[i]);
     case CHAR:
       return DatumFactory.createChar((byte[]) keys[i]);
     case BLOB:
       return DatumFactory.createBlob((byte[]) keys[i]);
     case DATUM:
       return (Datum) keys[i];
     default:
       throw new IllegalArgumentException();
   }
 }
Exemplo n.º 6
0
 @Override
 public final void addDouble(double value) {
   parent.add(DatumFactory.createFloat8(value));
 }
Exemplo n.º 7
0
 @Override
 public final void addFloat(float value) {
   parent.add(DatumFactory.createFloat8(Double.valueOf(value)));
 }