Esempio n. 1
0
 @Override
 protected void doEvaluate(
     TExecutionContext context, LazyList<? extends ValueSource> inputs, ValueTarget output) {
   double value = inputs.get(0).getDouble();
   if (value < 0) {
     output.putNull();
   } else {
     output.putDouble(Math.sqrt(value));
   }
 }
Esempio n. 2
0
 @Override
 protected void doEvaluate(
     TExecutionContext context, LazyList<? extends ValueSource> inputs, ValueTarget output) {
   String[] parts = {"", "", ""};
   if (covering.length == 1) {
     ColumnName columnName = ColumnName.parse("", inputs.get(0).getString());
     parts[0] = columnName.getTableName().getSchemaName();
     parts[1] = columnName.getTableName().getTableName();
     parts[2] = columnName.getName();
   } else {
     for (int i = covering.length - 1, j = 2; i >= 0; --i, --j) {
       parts[j] = inputs.get(i).getString();
     }
   }
   if (parts[0].isEmpty()) {
     parts[0] = context.getCurrentSchema();
   }
   AkibanInformationSchema ais = context.getQueryContext().getStore().schema().ais();
   Columnar columnar = ais.getTable(parts[0], parts[1]);
   if (columnar == null) {
     columnar = ais.getView(parts[0], parts[1]);
     if (columnar == null) {
       throw new NoSuchTableException(parts[0], parts[1]);
     }
   }
   Column column = columnar.getColumn(parts[2]);
   if (column == null) {
     throw new NoSuchColumnException(String.format("%s.%s.%s", parts[0], parts[1], parts[2]));
   }
   output.putString(column.getType().toStringConcise(false), null);
 }
Esempio n. 3
0
  protected boolean tryFromObject(TExecutionContext context, ValueSource in, ValueTarget out) {
    if (in.getType().equalsExcludingNullable(out.getType())) {
      ValueTargets.copyFrom(in, out);
      return true;
    }

    UnderlyingType underlyingType = TInstance.underlyingType(in.getType());
    if (underlyingType == UnderlyingType.STRING || underlyingType == UnderlyingType.BYTES)
      return false;
    final String asString;
    switch (underlyingType) {
      case BOOL:
        asString = Boolean.toString(in.getBoolean());
        break;
      case INT_8:
        asString = Byte.toString(in.getInt8());
        break;
      case INT_16:
        asString = Short.toString(in.getInt16());
        break;
      case UINT_16:
        asString = Integer.toString(in.getUInt16());
        break;
      case INT_32:
        asString = Integer.toString(in.getInt32());
        break;
      case INT_64:
        asString = Long.toString(in.getInt64());
        break;
      case FLOAT:
        asString = Float.toString(in.getFloat());
        break;
      case DOUBLE:
        asString = Double.toString(in.getDouble());
        break;
      case BYTES:
      case STRING:
      default:
        throw new AssertionError(underlyingType + ": " + in);
    }
    parser.parse(context, new Value(MString.varcharFor(asString), asString), out);
    return true;
  }
Esempio n. 4
0
 /** @see #getIntegerValue */
 public void setIntegerValue(ValueTarget target, long value) {
   switch (TInstance.underlyingType(target.getType())) {
     case INT_8:
       target.putInt8((byte) value);
       break;
     case INT_16:
       target.putInt16((short) value);
       break;
     case UINT_16:
       target.putUInt16((char) value);
       break;
     case INT_32:
       target.putInt32((int) value);
       break;
     case INT_64:
     default:
       target.putInt64(value);
   }
 }
Esempio n. 5
0
 @Override
 public void fromObject(TExecutionContext context, ValueSource in, ValueTarget out) {
   if (in.isNull()) out.putNull();
   else if (!tryFromObject(context, in, out)) parser.parse(context, in, out);
 }