Exemple #1
0
  @Override
  public Datum eval(Tuple params) {
    if (params.isBlankOrNull(0)) {
      return NullDatum.get();
    }

    return DatumFactory.createFloat8(Math.asin(params.getFloat8(0)));
  }
 public boolean equals(Tuple tuple) {
   for (int i = 0; i < keys.length; i++) {
     final int field = keyIndex[i];
     final boolean n1 = keys[i] == null;
     final boolean n2 = tuple.isBlankOrNull(field);
     if (n1 && n2) {
       continue;
     }
     if (n1 ^ n2) {
       return false;
     }
     switch (keyTypes[i]) {
       case BOOLEAN:
         if ((Boolean) keys[i] != tuple.getBool(field)) return false;
         continue;
       case BIT:
         if ((Byte) keys[i] != tuple.getByte(field)) return false;
         continue;
       case INT1:
       case INT2:
         if ((Short) keys[i] != tuple.getInt2(field)) return false;
         continue;
       case INT4:
       case DATE:
         if ((Integer) keys[i] != tuple.getInt4(field)) return false;
         continue;
       case INT8:
       case TIME:
       case TIMESTAMP:
         if ((Long) keys[i] != tuple.getInt8(field)) return false;
         continue;
       case FLOAT4:
         if ((Float) keys[i] != tuple.getFloat4(field)) return false;
         continue;
       case FLOAT8:
         if ((Double) keys[i] != tuple.getFloat8(field)) return false;
         continue;
       case TEXT:
       case CHAR:
       case BLOB:
         if (!Arrays.equals((byte[]) keys[i], tuple.getBytes(field))) return false;
         continue;
       case DATUM:
         if (!keys[i].equals(tuple.asDatum(field))) return false;
         continue;
     }
   }
   return true;
 }
 public void set(Tuple tuple) {
   for (int i = 0; i < keyTypes.length; i++) {
     final int field = keyIndex[i];
     if (tuple.isBlankOrNull(field)) {
       keys[i] = null;
       continue;
     }
     switch (keyTypes[i]) {
       case BOOLEAN:
         keys[i] = tuple.getBool(field);
         break;
       case BIT:
         keys[i] = tuple.getByte(field);
         break;
       case INT1:
       case INT2:
         keys[i] = tuple.getInt2(field);
         break;
       case INT4:
       case DATE:
         keys[i] = tuple.getInt4(field);
         break;
       case INT8:
       case TIME:
       case TIMESTAMP:
         keys[i] = tuple.getInt8(field);
         break;
       case FLOAT4:
         keys[i] = tuple.getFloat4(field);
         break;
       case FLOAT8:
         keys[i] = tuple.getFloat8(field);
         break;
       case TEXT:
       case CHAR:
       case BLOB:
         keys[i] = tuple.getBytes(field);
         break;
       case DATUM:
         keys[i] = tuple.asDatum(field);
         break;
       default:
         throw new IllegalArgumentException();
     }
   }
 }
  private void writeValue(Column column, Tuple tuple, int index) {
    switch (column.getDataType().getType()) {
      case BOOLEAN:
        recordConsumer.addBoolean(tuple.getBool(index));
        break;
      case BIT:
      case INT2:
      case INT4:
        recordConsumer.addInteger(tuple.getInt4(index));
        break;
      case INT8:
        recordConsumer.addLong(tuple.getInt8(index));
        break;
      case FLOAT4:
        recordConsumer.addFloat(tuple.getFloat4(index));
        break;
      case FLOAT8:
        recordConsumer.addDouble(tuple.getFloat8(index));
        break;
      case CHAR:
        if (tuple.size(index) > column.getDataType().getLength()) {
          throw new ValueTooLongForTypeCharactersException(column.getDataType().getLength());
        }

        recordConsumer.addBinary(Binary.fromByteArray(tuple.getTextBytes(index)));
        break;
      case TEXT:
        recordConsumer.addBinary(Binary.fromByteArray(tuple.getTextBytes(index)));
        break;
      case DATE:
        // Parquet DATE type is based on Unix Epoch(Jan 1, 1970).
        recordConsumer.addInteger(tuple.getInt4(index) - DateTimeConstants.UNIX_EPOCH_JDATE);
        break;
      case PROTOBUF:
      case BLOB:
        recordConsumer.addBinary(Binary.fromByteArray(tuple.getBytes(index)));
        break;
      default:
        break;
    }
  }
 protected final void set(int index, Tuple tuple, int field) {
   if (tuple.isBlankOrNull(field)) {
     nulls.set(index);
     return;
   }
   nulls.clear(index);
   switch (type) {
     case 0:
       booleans[index] = tuple.getBool(field);
       break;
     case 1:
       bits[index] = tuple.getByte(field);
       break;
     case 2:
       shorts[index] = tuple.getInt2(field);
       break;
     case 3:
       ints[index] = tuple.getInt4(field);
       break;
     case 4:
       longs[index] = tuple.getInt8(field);
       break;
     case 5:
       floats[index] = tuple.getFloat4(field);
       break;
     case 6:
       doubles[index] = tuple.getFloat8(field);
       break;
     case 7:
       bytes[index] = tuple.getBytes(field);
       break;
     case 8:
       ints[index] = tuple.getInt4(field);
       break;
     default:
       throw new IllegalArgumentException();
   }
 }