Exemplo n.º 1
0
 public static void input(Type type, NullableBooleanState state, Block block, int position) {
   if (!state.isNull()) {
     return;
   }
   state.setNull(false);
   state.setBoolean(type.getBoolean(block, position));
 }
Exemplo n.º 2
0
  @TypeParameter("T")
  @SqlType(StandardTypes.BOOLEAN)
  @Nullable
  public static Boolean contains(
      @TypeParameter("T") Type elementType,
      @OperatorDependency(
              operator = EQUAL,
              returnType = StandardTypes.BOOLEAN,
              argumentTypes = {"T", "T"})
          MethodHandle equals,
      @SqlType("array(T)") Block arrayBlock,
      @SqlType("T") boolean value) {
    boolean foundNull = false;
    for (int i = 0; i < arrayBlock.getPositionCount(); i++) {
      if (arrayBlock.isNull(i)) {
        foundNull = true;
        continue;
      }
      try {
        if ((boolean) equals.invokeExact(elementType.getBoolean(arrayBlock, i), value)) {
          return true;
        }
      } catch (Throwable t) {
        Throwables.propagateIfInstanceOf(t, Error.class);
        Throwables.propagateIfInstanceOf(t, PrestoException.class);

        throw new PrestoException(INTERNAL_ERROR, t);
      }
    }
    if (foundNull) {
      return null;
    }
    return false;
  }
Exemplo n.º 3
0
 @TypeParameter("T")
 @SqlType(StandardTypes.BIGINT)
 public static long arrayPosition(
     @TypeParameter("T") Type type,
     @OperatorDependency(
             operator = EQUAL,
             returnType = StandardTypes.BOOLEAN,
             argumentTypes = {"T", "T"})
         MethodHandle equalMethodHandle,
     @SqlType("array(T)") Block array,
     @SqlType("T") boolean element) {
   int size = array.getPositionCount();
   for (int i = 0; i < size; i++) {
     if (!array.isNull(i)) {
       boolean arrayValue = type.getBoolean(array, i);
       try {
         if ((boolean) equalMethodHandle.invokeExact(arrayValue, element)) {
           return i + 1; // result is 1-based (instead of 0)
         }
       } catch (Throwable t) {
         Throwables.propagateIfInstanceOf(t, Error.class);
         Throwables.propagateIfInstanceOf(t, PrestoException.class);
         throw new PrestoException(INTERNAL_ERROR, t);
       }
     }
   }
   return 0;
 }
  public static Boolean booleanElementAt(Type elementType, Block array, long index) {
    int position = checkedIndexToBlockPosition(array, index);
    if (array.isNull(position)) {
      return null;
    }

    return elementType.getBoolean(array, position);
  }
Exemplo n.º 5
0
  @UsedByGeneratedCode
  public static Boolean booleanSubscript(Type elementType, Block array, long index) {
    checkIndex(array, index);
    int position = Ints.checkedCast(index - 1);
    if (array.isNull(position)) {
      return null;
    }

    return elementType.getBoolean(array, position);
  }
Exemplo n.º 6
0
 private static void appendTo(Type type, SliceOutput output, Block block) {
   if (type.getJavaType() == long.class) {
     output.appendLong(type.getLong(block, 0));
   } else if (type.getJavaType() == double.class) {
     output.appendDouble(type.getDouble(block, 0));
   } else if (type.getJavaType() == Slice.class) {
     output.appendBytes(type.getSlice(block, 0));
   } else if (type.getJavaType() == boolean.class) {
     output.appendByte(type.getBoolean(block, 0) ? 1 : 0);
   } else {
     throw new IllegalArgumentException("Unsupported type: " + type.getJavaType().getSimpleName());
   }
 }
Exemplo n.º 7
0
Arquivo: Row.java Projeto: cdma/presto
 private static Object getNativeContainerValue(Type type, Block block, int position) {
   if (block.isNull(position)) {
     return null;
   } else if (type.getJavaType() == boolean.class) {
     return type.getBoolean(block, position);
   } else if (type.getJavaType() == long.class) {
     return type.getLong(block, position);
   } else if (type.getJavaType() == double.class) {
     return type.getDouble(block, position);
   } else if (type.getJavaType() == Slice.class) {
     return type.getSlice(block, position);
   } else if (type.getJavaType() == Block.class) {
     return type.getObject(block, position);
   } else {
     throw new AssertionError("Unimplemented type: " + type);
   }
 }