Java 类com.facebook.presto.spi.type.BooleanType 实例源码

项目:presto    文件:ShardPredicate.java   
public static JDBCType jdbcType(Type type)
{
    if (type.equals(BooleanType.BOOLEAN)) {
        return JDBCType.BOOLEAN;
    }
    if (type.equals(BigintType.BIGINT) || type.equals(TimestampType.TIMESTAMP)) {
        return JDBCType.BIGINT;
    }
    if (type.equals(DoubleType.DOUBLE)) {
        return JDBCType.DOUBLE;
    }
    if (type.equals(DateType.DATE)) {
        return JDBCType.INTEGER;
    }
    if (type.equals(VarcharType.VARCHAR)) {
        return JDBCType.VARBINARY;
    }
    return null;
}
项目:presto    文件:ShardStats.java   
private static ColumnStats doComputeColumnStats(OrcReader orcReader, long columnId, Type type)
        throws IOException
{
    int columnIndex = columnIndex(orcReader.getColumnNames(), columnId);
    OrcRecordReader reader = orcReader.createRecordReader(ImmutableMap.of(columnIndex, type), OrcPredicate.TRUE, UTC, new AggregatedMemoryContext());

    if (type.equals(BooleanType.BOOLEAN)) {
        return indexBoolean(type, reader, columnIndex, columnId);
    }
    if (type.equals(BigintType.BIGINT) ||
            type.equals(DateType.DATE) ||
            type.equals(TimestampType.TIMESTAMP)) {
        return indexLong(type, reader, columnIndex, columnId);
    }
    if (type.equals(DoubleType.DOUBLE)) {
        return indexDouble(type, reader, columnIndex, columnId);
    }
    if (type.equals(VarcharType.VARCHAR)) {
        return indexString(type, reader, columnIndex, columnId);
    }
    return null;
}
项目:presto    文件:FieldSetFilteringRecordSet.java   
public FieldSetFilteringRecordSet(FunctionRegistry functionRegistry, RecordSet delegate, List<Set<Integer>> fieldSets)
{
    requireNonNull(functionRegistry, "functionRegistry is null");
    this.delegate = requireNonNull(delegate, "delegate is null");

    ImmutableList.Builder<Set<Field>> fieldSetsBuilder = ImmutableList.builder();
    List<Type> columnTypes = delegate.getColumnTypes();
    for (Set<Integer> fieldSet : requireNonNull(fieldSets, "fieldSets is null")) {
        ImmutableSet.Builder<Field> fieldSetBuilder = ImmutableSet.builder();
        for (int field : fieldSet) {
            fieldSetBuilder.add(new Field(
                    field,
                    functionRegistry.getScalarFunctionImplementation(internalOperator(OperatorType.EQUAL, BooleanType.BOOLEAN, ImmutableList.of(columnTypes.get(field), columnTypes.get(field)))).getMethodHandle()));
        }
        fieldSetsBuilder.add(fieldSetBuilder.build());
    }
    this.fieldSets = fieldSetsBuilder.build();
}
项目:presto    文件:ArrayContains.java   
@Override
public ScalarFunctionImplementation specialize(Map<String, Type> types, int arity, TypeManager typeManager, FunctionRegistry functionRegistry)
{
    Type type = types.get("T");

    MethodHandle methodHandle;
    MethodHandle equalsHandle = functionRegistry.getScalarFunctionImplementation(internalOperator(OperatorType.EQUAL, BooleanType.BOOLEAN, ImmutableList.of(type, type))).getMethodHandle();

    List<Boolean> nullableArguments;
    if (type.getJavaType() == void.class) {
        nullableArguments = ImmutableList.of(false, true);
        methodHandle = METHOD_HANDLE_UNKNOWN;
    }
    else {
        nullableArguments = ImmutableList.of(false, false);
        methodHandle = methodHandle(ArrayContains.class, "contains", Type.class, MethodHandle.class, Block.class, type.getJavaType());
    }

    return new ScalarFunctionImplementation(true, nullableArguments, methodHandle.bindTo(type).bindTo(equalsHandle), isDeterministic());
}
项目:presto    文件:SessionPropertyManager.java   
@NotNull
public static String serializeSessionProperty(Type type, Object value)
{
    if (value == null) {
        throw new PrestoException(INVALID_SESSION_PROPERTY, "Session property can not be null");
    }
    if (BooleanType.BOOLEAN.equals(type)) {
        return value.toString();
    }
    if (BigintType.BIGINT.equals(type)) {
        return value.toString();
    }
    if (DoubleType.DOUBLE.equals(type)) {
        return value.toString();
    }
    if (VarcharType.VARCHAR.equals(type)) {
        return value.toString();
    }
    if (type instanceof ArrayType || type instanceof MapType) {
        return getJsonCodecForType(type).toJson(value);
    }
    throw new PrestoException(INVALID_SESSION_PROPERTY, format("Session property type %s is not supported", type));
}
项目:presto    文件:SessionPropertyManager.java   
@NotNull
private static Object deserializeSessionProperty(Type type, String value)
{
    if (value == null) {
        throw new PrestoException(INVALID_SESSION_PROPERTY, "Session property can not be null");
    }
    if (VarcharType.VARCHAR.equals(type)) {
        return value;
    }
    if (BooleanType.BOOLEAN.equals(type)) {
        return Boolean.valueOf(value);
    }
    if (BigintType.BIGINT.equals(type)) {
        return Long.valueOf(value);
    }
    if (DoubleType.DOUBLE.equals(type)) {
        return Double.valueOf(value);
    }
    if (type instanceof ArrayType || type instanceof MapType) {
        return getJsonCodecForType(type).fromJson(value);
    }
    throw new PrestoException(INVALID_SESSION_PROPERTY, format("Session property type %s is not supported", type));
}
项目:presto    文件:SessionPropertyManager.java   
private static <T> JsonCodec<T> getJsonCodecForType(Type type)
{
    if (VarcharType.VARCHAR.equals(type)) {
        return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(String.class);
    }
    if (BooleanType.BOOLEAN.equals(type)) {
        return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Boolean.class);
    }
    if (BigintType.BIGINT.equals(type)) {
        return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Long.class);
    }
    if (DoubleType.DOUBLE.equals(type)) {
        return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Double.class);
    }
    if (type instanceof ArrayType) {
        Type elementType = ((ArrayType) type).getElementType();
        return (JsonCodec<T>) JSON_CODEC_FACTORY.listJsonCodec(getJsonCodecForType(elementType));
    }
    if (type instanceof MapType) {
        Type keyType = ((MapType) type).getKeyType();
        Type valueType = ((MapType) type).getValueType();
        return (JsonCodec<T>) JSON_CODEC_FACTORY.mapJsonCodec(getMapKeyType(keyType), getJsonCodecForType(valueType));
    }
    throw new PrestoException(INVALID_SESSION_PROPERTY, format("Session property type %s is not supported", type));
}
项目:presto    文件:SessionPropertyManager.java   
private static Class<?> getMapKeyType(Type type)
{
    if (VarcharType.VARCHAR.equals(type)) {
        return String.class;
    }
    if (BooleanType.BOOLEAN.equals(type)) {
        return Boolean.class;
    }
    if (BigintType.BIGINT.equals(type)) {
        return Long.class;
    }
    if (DoubleType.DOUBLE.equals(type)) {
        return Double.class;
    }
    throw new PrestoException(INVALID_SESSION_PROPERTY, format("Session property map key type %s is not supported", type));
}
项目:presto    文件:TestStateCompiler.java   
@Test
public void testPrimitiveBooleanSerialization()
{
    StateCompiler compiler = new StateCompiler();

    AccumulatorStateFactory<BooleanState> factory = compiler.generateStateFactory(BooleanState.class);
    AccumulatorStateSerializer<BooleanState> serializer = compiler.generateStateSerializer(BooleanState.class);
    BooleanState state = factory.createSingleState();
    BooleanState deserializedState = factory.createSingleState();

    state.setBoolean(true);

    BlockBuilder builder = BooleanType.BOOLEAN.createBlockBuilder(new BlockBuilderStatus(), 1);
    serializer.serialize(state, builder);

    Block block = builder.build();
    serializer.deserialize(block, 0, deserializedState);
    assertEquals(deserializedState.getBoolean(), state.getBoolean());
}
项目:presto    文件:TestPageProcessorCompiler.java   
@Test
public void testNoCaching()
        throws Throwable
{
    MetadataManager metadata = MetadataManager.createTestMetadataManager();
    ExpressionCompiler compiler = new ExpressionCompiler(metadata);
    ImmutableList.Builder<RowExpression> projectionsBuilder = ImmutableList.builder();
    ArrayType arrayType = new ArrayType(VARCHAR);
    Signature signature = new Signature("concat", FunctionKind.SCALAR, arrayType.getTypeSignature(), arrayType.getTypeSignature(), arrayType.getTypeSignature());
    projectionsBuilder.add(new CallExpression(signature, arrayType, ImmutableList.of(new InputReferenceExpression(0, arrayType), new InputReferenceExpression(1, arrayType))));

    ImmutableList<RowExpression> projections = projectionsBuilder.build();
    PageProcessor pageProcessor = compiler.compilePageProcessor(new ConstantExpression(true, BooleanType.BOOLEAN), projections);
    PageProcessor pageProcessor2 = compiler.compilePageProcessor(new ConstantExpression(true, BooleanType.BOOLEAN), projections);
    assertTrue(pageProcessor != pageProcessor2);
}
项目:presto    文件:BenchmarkArrayDistinct.java   
@Setup
public void setup()
{
    MetadataManager metadata = MetadataManager.createTestMetadataManager();
    metadata.addFunctions(new FunctionListBuilder(metadata.getTypeManager()).scalar(BenchmarkArrayDistinct.class).getFunctions());
    ExpressionCompiler compiler = new ExpressionCompiler(metadata);
    ImmutableList.Builder<RowExpression> projectionsBuilder = ImmutableList.builder();
    Block[] blocks = new Block[TYPES.size()];
    for (int i = 0; i < TYPES.size(); i++) {
        Type elementType = TYPES.get(i);
        ArrayType arrayType = new ArrayType(elementType);
        Signature signature = new Signature(name, FunctionKind.SCALAR, arrayType.getTypeSignature(), arrayType.getTypeSignature());
        projectionsBuilder.add(new CallExpression(signature, arrayType, ImmutableList.of(new InputReferenceExpression(i, arrayType))));
        blocks[i] = createChannel(POSITIONS, ARRAY_SIZE, arrayType);
    }

    ImmutableList<RowExpression> projections = projectionsBuilder.build();
    pageProcessor = compiler.compilePageProcessor(new ConstantExpression(true, BooleanType.BOOLEAN), projections);
    pageBuilder = new PageBuilder(projections.stream().map(RowExpression::getType).collect(Collectors.toList()));
    page = new Page(blocks);
}
项目:presto    文件:TestJsonDecoder.java   
@Test
public void testNonExistent()
        throws Exception
{
    byte[] json = "{}".getBytes(StandardCharsets.UTF_8);

    JsonRowDecoder rowDecoder = new JsonRowDecoder(PROVIDER.get());
    DecoderTestColumnHandle row1 = new DecoderTestColumnHandle("", 0, "row1", VarcharType.VARCHAR, "very/deep/varchar", null, null, false, false, false);
    DecoderTestColumnHandle row2 = new DecoderTestColumnHandle("", 1, "row2", BigintType.BIGINT, "no_bigint", null, null, false, false, false);
    DecoderTestColumnHandle row3 = new DecoderTestColumnHandle("", 2, "row3", DoubleType.DOUBLE, "double/is_missing", null, null, false, false, false);
    DecoderTestColumnHandle row4 = new DecoderTestColumnHandle("", 3, "row4", BooleanType.BOOLEAN, "hello", null, null, false, false, false);

    List<DecoderColumnHandle> columns = ImmutableList.of(row1, row2, row3, row4);
    Set<FieldValueProvider> providers = new HashSet<>();

    boolean corrupt = rowDecoder.decodeRow(json, null, providers, columns, buildMap(columns));
    assertFalse(corrupt);

    assertEquals(providers.size(), columns.size());

    checkIsNull(providers, row1);
    checkIsNull(providers, row2);
    checkIsNull(providers, row3);
    checkIsNull(providers, row4);
}
项目:presto    文件:TestCsvDecoder.java   
@Test
public void testNulls()
{
    String csv = ",,,";

    CsvRowDecoder rowDecoder = new CsvRowDecoder();

    DecoderTestColumnHandle row1 = new DecoderTestColumnHandle("", 0, "row1", VarcharType.VARCHAR, "0", null, null, false, false, false);
    DecoderTestColumnHandle row2 = new DecoderTestColumnHandle("", 1, "row2", BigintType.BIGINT, "1", null, null, false, false, false);
    DecoderTestColumnHandle row3 = new DecoderTestColumnHandle("", 2, "row3", DoubleType.DOUBLE, "2", null, null, false, false, false);
    DecoderTestColumnHandle row4 = new DecoderTestColumnHandle("", 3, "row4", BooleanType.BOOLEAN, "3", null, null, false, false, false);

    List<DecoderColumnHandle> columns = ImmutableList.of(row1, row2, row3, row4);

    Set<FieldValueProvider> providers = new HashSet<>();

    boolean corrupt = rowDecoder.decodeRow(csv.getBytes(StandardCharsets.UTF_8), null, providers, columns, buildMap(columns));
    assertFalse(corrupt);

    assertEquals(providers.size(), columns.size());

    checkValue(providers, row1, "");
    checkValue(providers, row2, 0);
    checkValue(providers, row3, 0.0d);
    checkValue(providers, row4, false);
}
项目:presto-kinesis    文件:TestJsonDecoder.java   
@Test
public void testNonExistent()
        throws Exception
{
    byte[] json = "{}".getBytes(StandardCharsets.UTF_8);

    JsonKinesisRowDecoder rowDecoder = new JsonKinesisRowDecoder(PROVIDER.get());
    KinesisColumnHandle row1 = new KinesisColumnHandle("", 0, "row1", VarcharType.VARCHAR, "very/deep/varchar", null, null, false, false);
    KinesisColumnHandle row2 = new KinesisColumnHandle("", 1, "row2", BigintType.BIGINT, "no_bigint", null, null, false, false);
    KinesisColumnHandle row3 = new KinesisColumnHandle("", 2, "row3", DoubleType.DOUBLE, "double/is_missing", null, null, false, false);
    KinesisColumnHandle row4 = new KinesisColumnHandle("", 3, "row4", BooleanType.BOOLEAN, "hello", null, null, false, false);

    List<KinesisColumnHandle> columns = ImmutableList.of(row1, row2, row3, row4);
    Set<KinesisFieldValueProvider> providers = new HashSet<>();

    boolean valid = rowDecoder.decodeRow(json, providers, columns, buildMap(columns));
    assertTrue(valid);

    assertEquals(providers.size(), columns.size());

    DecoderTestUtil.checkIsNull(providers, row1);
    DecoderTestUtil.checkIsNull(providers, row2);
    DecoderTestUtil.checkIsNull(providers, row3);
    DecoderTestUtil.checkIsNull(providers, row4);
}
项目:presto-riak    文件:TestRiakColumnHandle.java   
@Test
public void testSerializtion2()
        throws IOException
{
    String connectorId = "fooo gooo";
    RiakColumn column = new RiakColumn("p", BooleanType.BOOLEAN, "boom", true, false);
    RiakColumnHandle c = new RiakColumnHandle(connectorId, column, 4);
    assert(c.getColumn().getType() == BooleanType.BOOLEAN);

    String s = COLUMN_CODEC.toJson(c);
    System.out.println(s);

    RiakColumnHandle c2 = COLUMN_CODEC.fromJson(s);

    assert(c.equals(c2));
    assert(c.getColumn().getType() == BooleanType.BOOLEAN);
    assert(c2.getColumn().getType() == BooleanType.BOOLEAN);
    System.out.println(c);
    System.out.println(c2);
}
项目:presto    文件:QueryBuilder.java   
private List<String> toConjuncts(List<JdbcColumnHandle> columns, TupleDomain<ColumnHandle> tupleDomain)
{
    ImmutableList.Builder<String> builder = ImmutableList.builder();
    for (JdbcColumnHandle column : columns) {
        Type type = column.getColumnType();
        if (type.equals(BigintType.BIGINT) || type.equals(DoubleType.DOUBLE) || type.equals(BooleanType.BOOLEAN)) {
            Domain domain = tupleDomain.getDomains().get().get(column);
            if (domain != null) {
                builder.add(toPredicate(column.getColumnName(), domain));
            }
        }
    }
    return builder.build();
}
项目:presto    文件:MapSubscriptOperator.java   
@Override
public ScalarFunctionImplementation specialize(Map<String, Type> types, int arity, TypeManager typeManager, FunctionRegistry functionRegistry)
{
    Type keyType = types.get("K");
    Type valueType = types.get("V");

    MethodHandle keyEqualsMethod = functionRegistry.getScalarFunctionImplementation(internalOperator(OperatorType.EQUAL, BooleanType.BOOLEAN, ImmutableList.of(keyType, keyType))).getMethodHandle();

    MethodHandle methodHandle;
    if (keyType.getJavaType() == boolean.class) {
        methodHandle = METHOD_HANDLE_BOOLEAN;
    }
    else if (keyType.getJavaType() == long.class) {
        methodHandle = METHOD_HANDLE_LONG;
    }
    else if (keyType.getJavaType() == double.class) {
        methodHandle = METHOD_HANDLE_DOUBLE;
    }
    else if (keyType.getJavaType() == Slice.class) {
        methodHandle = METHOD_HANDLE_SLICE;
    }
    else {
        methodHandle = METHOD_HANDLE_OBJECT;
    }
    methodHandle = methodHandle.bindTo(keyEqualsMethod).bindTo(keyType).bindTo(valueType);

    // this casting is necessary because otherwise presto byte code generator will generate illegal byte code
    if (valueType.getJavaType() == void.class) {
        methodHandle = methodHandle.asType(methodHandle.type().changeReturnType(void.class));
    }
    else {
        methodHandle = methodHandle.asType(methodHandle.type().changeReturnType(Primitives.wrap(valueType.getJavaType())));
    }

    return new ScalarFunctionImplementation(true, ImmutableList.of(false, false), methodHandle, isDeterministic());
}
项目:presto    文件:TestChecksumAggregation.java   
@Test
public void testBoolean()
    throws Exception
{
    InternalAggregationFunction booleanAgg = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature("checksum", AGGREGATE, VARBINARY, BOOLEAN));
    Block block = createBooleansBlock(null, null, true, false, false);
    assertAggregation(booleanAgg, 1.0, expectedChecksum(BooleanType.BOOLEAN, block), block);
}
项目:presto    文件:HiveWriteUtils.java   
public static ObjectInspector getRowColumnInspector(Type type)
{
    if (type.equals(BooleanType.BOOLEAN)) {
        return writableBooleanObjectInspector;
    }

    if (type.equals(BigintType.BIGINT)) {
        return writableLongObjectInspector;
    }

    if (type.equals(DoubleType.DOUBLE)) {
        return writableDoubleObjectInspector;
    }

    if (type.equals(VarcharType.VARCHAR)) {
        return writableStringObjectInspector;
    }

    if (type.equals(VarbinaryType.VARBINARY)) {
        return writableBinaryObjectInspector;
    }

    if (type.equals(DateType.DATE)) {
        return writableDateObjectInspector;
    }

    if (type.equals(TimestampType.TIMESTAMP)) {
        return writableTimestampObjectInspector;
    }

    if (isArrayType(type) || isMapType(type) || isRowType(type)) {
        return getJavaObjectInspector(type);
    }

    throw new IllegalArgumentException("unsupported type: " + type);
}
项目:presto    文件:TestJsonDecoder.java   
@Test
public void testSimple()
        throws Exception
{
    byte[] json = ByteStreams.toByteArray(TestJsonDecoder.class.getResourceAsStream("/decoder/json/message.json"));

    JsonRowDecoder rowDecoder = new JsonRowDecoder(PROVIDER.get());
    DecoderTestColumnHandle row1 = new DecoderTestColumnHandle("", 0, "row1", VarcharType.VARCHAR, "source", null, null, false, false, false);
    DecoderTestColumnHandle row2 = new DecoderTestColumnHandle("", 1, "row2", VarcharType.VARCHAR, "user/screen_name", null, null, false, false, false);
    DecoderTestColumnHandle row3 = new DecoderTestColumnHandle("", 2, "row3", BigintType.BIGINT, "id", null, null, false, false, false);
    DecoderTestColumnHandle row4 = new DecoderTestColumnHandle("", 3, "row4", BigintType.BIGINT, "user/statuses_count", null, null, false, false, false);
    DecoderTestColumnHandle row5 = new DecoderTestColumnHandle("", 4, "row5", BooleanType.BOOLEAN, "user/geo_enabled", null, null, false, false, false);

    List<DecoderColumnHandle> columns = ImmutableList.of(row1, row2, row3, row4, row5);
    Set<FieldValueProvider> providers = new HashSet<>();

    boolean corrupt = rowDecoder.decodeRow(json, null, providers, columns, buildMap(columns));
    assertFalse(corrupt);

    assertEquals(providers.size(), columns.size());

    checkValue(providers, row1, "<a href=\"http://twitterfeed.com\" rel=\"nofollow\">twitterfeed</a>");
    checkValue(providers, row2, "EKentuckyNews");
    checkValue(providers, row3, 493857959588286460L);
    checkValue(providers, row4, 7630);
    checkValue(providers, row5, true);
}
项目:presto    文件:TestCsvDecoder.java   
@Test
public void testBoolean()
{
    String csv = "True,False,0,1,\"0\",\"1\",\"true\",\"false\"";

    CsvRowDecoder rowDecoder = new CsvRowDecoder();

    DecoderTestColumnHandle row1 = new DecoderTestColumnHandle("", 0, "row1", BooleanType.BOOLEAN, "0", null, null, false, false, false);
    DecoderTestColumnHandle row2 = new DecoderTestColumnHandle("", 1, "row2", BooleanType.BOOLEAN, "1", null, null, false, false, false);
    DecoderTestColumnHandle row3 = new DecoderTestColumnHandle("", 2, "row3", BooleanType.BOOLEAN, "2", null, null, false, false, false);
    DecoderTestColumnHandle row4 = new DecoderTestColumnHandle("", 3, "row4", BooleanType.BOOLEAN, "3", null, null, false, false, false);
    DecoderTestColumnHandle row5 = new DecoderTestColumnHandle("", 4, "row5", BooleanType.BOOLEAN, "4", null, null, false, false, false);
    DecoderTestColumnHandle row6 = new DecoderTestColumnHandle("", 5, "row6", BooleanType.BOOLEAN, "5", null, null, false, false, false);
    DecoderTestColumnHandle row7 = new DecoderTestColumnHandle("", 6, "row7", BooleanType.BOOLEAN, "6", null, null, false, false, false);
    DecoderTestColumnHandle row8 = new DecoderTestColumnHandle("", 7, "row8", BooleanType.BOOLEAN, "7", null, null, false, false, false);

    List<DecoderColumnHandle> columns = ImmutableList.of(row1, row2, row3, row4, row5, row6, row7, row8);

    Set<FieldValueProvider> providers = new HashSet<>();

    boolean corrupt = rowDecoder.decodeRow(csv.getBytes(StandardCharsets.UTF_8), null, providers, columns, buildMap(columns));
    assertFalse(corrupt);

    assertEquals(providers.size(), columns.size());

    checkValue(providers, row1, true);
    checkValue(providers, row2, false);
    checkValue(providers, row3, false);
    checkValue(providers, row4, false);
    checkValue(providers, row5, false);
    checkValue(providers, row6, false);
    checkValue(providers, row7, true);
    checkValue(providers, row8, false);
}
项目:presto-plugins    文件:SpreadsheetMetadata.java   
private Type getType(TableType columnType) {
  switch (columnType) {
  case BOOLEAN:
    return BooleanType.BOOLEAN;
  case NUMBER:
    return DoubleType.DOUBLE;
  case STRING:
    return VarcharType.VARCHAR;
  default:
    throw new PrestoException(SpreadsheetErrorCode.INTERNAL_ERROR, "Not Supported [" + columnType + "]");
  }
}
项目:presto-kinesis    文件:TestJsonDecoder.java   
@Test
public void testSimple()
        throws Exception
{
    byte[] json = ByteStreams.toByteArray(TestJsonDecoder.class.getResourceAsStream("/decoder/json/message.json"));

    JsonKinesisRowDecoder rowDecoder = new JsonKinesisRowDecoder(PROVIDER.get());
    KinesisColumnHandle row1 = new KinesisColumnHandle("", 0, "row1", VarcharType.VARCHAR, "source", null, null, false, false);
    KinesisColumnHandle row2 = new KinesisColumnHandle("", 1, "row2", VarcharType.VARCHAR, "user/screen_name", null, null, false, false);
    KinesisColumnHandle row3 = new KinesisColumnHandle("", 2, "row3", BigintType.BIGINT, "id", null, null, false, false);
    KinesisColumnHandle row4 = new KinesisColumnHandle("", 3, "row4", BigintType.BIGINT, "user/statuses_count", null, null, false, false);
    KinesisColumnHandle row5 = new KinesisColumnHandle("", 4, "row5", BooleanType.BOOLEAN, "user/geo_enabled", null, null, false, false);

    List<KinesisColumnHandle> columns = ImmutableList.of(row1, row2, row3, row4, row5);
    Set<KinesisFieldValueProvider> providers = new HashSet<>();

    boolean valid = rowDecoder.decodeRow(json, providers, columns, buildMap(columns));
    assertTrue(valid);

    assertEquals(providers.size(), columns.size());

    DecoderTestUtil.checkValue(providers, row1, "<a href=\"http://twitterfeed.com\" rel=\"nofollow\">twitterfeed</a>");
    DecoderTestUtil.checkValue(providers, row2, "EKentuckyNews");
    DecoderTestUtil.checkValue(providers, row3, 493857959588286460L);
    DecoderTestUtil.checkValue(providers, row4, 7630);
    DecoderTestUtil.checkValue(providers, row5, true);
}
项目:paraflow    文件:MetaDataQuery.java   
private Type getType(String typeName)
{
    log.debug("Get type " + typeName);
    typeName = typeName.toLowerCase();
    // check if type is varchar(xx)
    Pattern vcpattern = Pattern.compile("varchar\\(\\s*(\\d+)\\s*\\)");
    Matcher vcmatcher = vcpattern.matcher(typeName);
    if (vcmatcher.find()) {
        String vlen = vcmatcher.group(1);
        if (!vlen.isEmpty()) {
            return VarcharType.createVarcharType(Integer.parseInt(vlen));
        }
        return UnknownType.UNKNOWN;
    }
    // check if type is char(xx)
    Pattern cpattern = Pattern.compile("char\\(\\s*(\\d+)\\s*\\)");
    Matcher cmatcher = cpattern.matcher(typeName);
    if (cmatcher.find()) {
        String clen = cmatcher.group(1);
        if (!clen.isEmpty()) {
            return CharType.createCharType(Integer.parseInt(clen));
        }
        return UnknownType.UNKNOWN;
    }
    // check if type is decimal(precision, scale)
    Pattern dpattern = Pattern.compile("decimal\\((\\d+)\\s*,?\\s*(\\d*)\\)");
    Matcher dmatcher = dpattern.matcher(typeName);
    if (dmatcher.find()) {
        String dprecision = dmatcher.group(1);
        String dscale = dmatcher.group(2);
        if (dprecision.isEmpty()) {
            return UnknownType.UNKNOWN;
        }
        if (dscale.isEmpty()) {
            return DecimalType.createDecimalType(Integer.parseInt(dprecision));
        }
        return DecimalType.createDecimalType(Integer.parseInt(dprecision), Integer.parseInt(dscale));
    }
    switch (typeName) {
        case "boolean": return BooleanType.BOOLEAN;
        case "tinyint": return TinyintType.TINYINT;
        case "smallint": return SmallintType.SMALLINT;
        case "integer": return IntegerType.INTEGER;
        case "bigint": return BigintType.BIGINT;
        case "real": return RealType.REAL;
        case "double": return DoubleType.DOUBLE;
        case "date": return DateType.DATE;
        case "time": return TimeType.TIME;
        case "timestamp": return TimestampType.TIMESTAMP;
        default: return UnknownType.UNKNOWN;
    }
}
项目:presto    文件:BooleanOrAggregation.java   
@OutputFunction(StandardTypes.BOOLEAN)
public static void output(TriStateBooleanState state, BlockBuilder out)
{
    TriStateBooleanState.write(BooleanType.BOOLEAN, state, out);
}
项目:presto    文件:BooleanAndAggregation.java   
@OutputFunction(StandardTypes.BOOLEAN)
public static void output(TriStateBooleanState state, BlockBuilder out)
{
    TriStateBooleanState.write(BooleanType.BOOLEAN, state, out);
}
项目:presto    文件:HiveWriteUtils.java   
public static ObjectInspector getJavaObjectInspector(Type type)
{
    if (type.equals(BooleanType.BOOLEAN)) {
        return javaBooleanObjectInspector;
    }
    else if (type.equals(BigintType.BIGINT)) {
        return javaLongObjectInspector;
    }
    else if (type.equals(DoubleType.DOUBLE)) {
        return javaDoubleObjectInspector;
    }
    else if (type.equals(VarcharType.VARCHAR)) {
        return writableStringObjectInspector;
    }
    else if (type.equals(VarbinaryType.VARBINARY)) {
        return javaByteArrayObjectInspector;
    }
    else if (type.equals(DateType.DATE)) {
        return javaDateObjectInspector;
    }
    else if (type.equals(TimestampType.TIMESTAMP)) {
        return javaTimestampObjectInspector;
    }
    else if (isArrayType(type)) {
        return ObjectInspectorFactory.getStandardListObjectInspector(getJavaObjectInspector(type.getTypeParameters().get(0)));
    }
    else if (isMapType(type)) {
        ObjectInspector keyObjectInspector = getJavaObjectInspector(type.getTypeParameters().get(0));
        ObjectInspector valueObjectInspector = getJavaObjectInspector(type.getTypeParameters().get(1));
        return ObjectInspectorFactory.getStandardMapObjectInspector(keyObjectInspector, valueObjectInspector);
    }
    else if (isRowType(type)) {
        return ObjectInspectorFactory.getStandardStructObjectInspector(
                type.getTypeSignature().getParameters().stream()
                        .map(parameter -> parameter.getNamedTypeSignature().getName())
                        .collect(toList()),
                type.getTypeParameters().stream()
                        .map(HiveWriteUtils::getJavaObjectInspector)
                        .collect(toList()));
    }
    throw new IllegalArgumentException("unsupported type: " + type);
}
项目:presto    文件:HiveWriteUtils.java   
public static FieldSetter createFieldSetter(SettableStructObjectInspector rowInspector, Object row, StructField field, Type type)
{
    if (type.equals(BooleanType.BOOLEAN)) {
        return new BooleanFieldSetter(rowInspector, row, field);
    }

    if (type.equals(BigintType.BIGINT)) {
        return new BigintFieldBuilder(rowInspector, row, field);
    }

    if (type.equals(DoubleType.DOUBLE)) {
        return new DoubleFieldSetter(rowInspector, row, field);
    }

    if (type.equals(VarcharType.VARCHAR)) {
        return new VarcharFieldSetter(rowInspector, row, field);
    }

    if (type.equals(VarbinaryType.VARBINARY)) {
        return new BinaryFieldSetter(rowInspector, row, field);
    }

    if (type.equals(DateType.DATE)) {
        return new DateFieldSetter(rowInspector, row, field);
    }

    if (type.equals(TimestampType.TIMESTAMP)) {
        return new TimestampFieldSetter(rowInspector, row, field);
    }

    if (isArrayType(type)) {
        return new ArrayFieldSetter(rowInspector, row, field, type.getTypeParameters().get(0));
    }

    if (isMapType(type)) {
        return new MapFieldSetter(rowInspector, row, field, type.getTypeParameters().get(0), type.getTypeParameters().get(1));
    }

    if (isRowType(type)) {
        return new RowFieldSetter(rowInspector, row, field, type.getTypeParameters());
    }

    throw new IllegalArgumentException("unsupported type: " + type);
}
项目:presto    文件:HiveWriteUtils.java   
@Override
public void setField(Block block, int position)
{
    value.set(BooleanType.BOOLEAN.getBoolean(block, position));
    rowInspector.setStructFieldData(row, field, value);
}
项目:presto    文件:SerDeUtils.java   
private static void serializePrimitive(BlockBuilder builder, Object object, PrimitiveObjectInspector inspector)
{
    requireNonNull(builder, "parent builder is null");

    if (object == null) {
        builder.appendNull();
        return;
    }

    switch (inspector.getPrimitiveCategory()) {
        case BOOLEAN:
            BooleanType.BOOLEAN.writeBoolean(builder, ((BooleanObjectInspector) inspector).get(object));
            return;
        case BYTE:
            BigintType.BIGINT.writeLong(builder, ((ByteObjectInspector) inspector).get(object));
            return;
        case SHORT:
            BigintType.BIGINT.writeLong(builder, ((ShortObjectInspector) inspector).get(object));
            return;
        case INT:
            BigintType.BIGINT.writeLong(builder, ((IntObjectInspector) inspector).get(object));
            return;
        case LONG:
            BigintType.BIGINT.writeLong(builder, ((LongObjectInspector) inspector).get(object));
            return;
        case FLOAT:
            DoubleType.DOUBLE.writeDouble(builder, ((FloatObjectInspector) inspector).get(object));
            return;
        case DOUBLE:
            DoubleType.DOUBLE.writeDouble(builder, ((DoubleObjectInspector) inspector).get(object));
            return;
        case STRING:
            VarcharType.VARCHAR.writeSlice(builder, Slices.utf8Slice(((StringObjectInspector) inspector).getPrimitiveJavaObject(object)));
            return;
        case DATE:
            DateType.DATE.writeLong(builder, formatDateAsLong(object, (DateObjectInspector) inspector));
            return;
        case TIMESTAMP:
            TimestampType.TIMESTAMP.writeLong(builder, formatTimestampAsLong(object, (TimestampObjectInspector) inspector));
            return;
        case BINARY:
            VARBINARY.writeSlice(builder, Slices.wrappedBuffer(((BinaryObjectInspector) inspector).getPrimitiveJavaObject(object)));
            return;
    }
    throw new RuntimeException("Unknown primitive type: " + inspector.getPrimitiveCategory());
}
项目:presto-riak    文件:RiakRecordCursor.java   
@Override
public boolean getBoolean(int field) {
    checkFieldType(field, BooleanType.BOOLEAN);
    return Boolean.parseBoolean(getFieldValue(field));
}