Package com.facebook.presto.spi.type

Examples of com.facebook.presto.spi.type.Type


    private void append(int channel, Object value)
    {
        BlockBuilder builder = builders.get(channel);

        Type type = types.get(channel);
        Class<?> javaType = type.getJavaType();
        if (value == null) {
            builder.appendNull();
        }
        else if (javaType == boolean.class) {
            type.writeBoolean(builder, (Boolean) value);
        }
        else if (javaType == long.class) {
            type.writeLong(builder, ((Number) value).longValue());
        }
        else if (javaType == double.class) {
            type.writeDouble(builder, (Double) value);
        }
        else if (javaType == Slice.class) {
            Slice slice = Slices.utf8Slice((String) value);
            type.writeSlice(builder, slice, 0, slice.length());
        }
        else {
            throw new IllegalArgumentException("bad value: " + value.getClass().getName());
        }
    }
View Full Code Here


                SQL_PARSER,
                TEST_SESSION
        );

        // create output
        Type type = projectionFunction.getType();
        BlockBuilder builder = type.createBlockBuilder(new BlockBuilderStatus());

        // project
        projectionFunction.project(position, blocks, builder);

        // extract single value
View Full Code Here

        return new IsNullPredicate(reference(symbol));
    }

    private static InPredicate in(Symbol symbol, List<?> values)
    {
        Type type = TYPES.get(symbol);
        return new InPredicate(reference(symbol), new InListExpression(LiteralInterpreter.toExpressions(values, Collections.nCopies(values.size(), type))));
    }
View Full Code Here

    public static Page createSequencePage(List<? extends Type> types, int length, int... initialValues)
    {
        Block[] blocks = new Block[initialValues.length];
        for (int i = 0; i < blocks.length; i++) {
            Type type = types.get(i);
            int initialValue = initialValues[i];

            if (type.equals(BIGINT)) {
                blocks[i] = BlockAssertions.createLongSequenceBlock(initialValue, initialValue + length);
            }
            else if (type.equals(DOUBLE)) {
                blocks[i] = BlockAssertions.createDoubleSequenceBlock(initialValue, initialValue + length);
            }
            else if (type.equals(VARCHAR)) {
                blocks[i] = BlockAssertions.createStringSequenceBlock(initialValue, initialValue + length);
            }
            else if (type.equals(BOOLEAN)) {
                blocks[i] = BlockAssertions.createBooleanSequenceBlock(initialValue, initialValue + length);
            }
            else {
                throw new IllegalStateException("Unsupported type " + type);
            }
View Full Code Here

        Page output = getAtMostOnePage(operator, SOURCE_PAGE);

        assertNotNull(output);
        assertEquals(output.getPositionCount(), 1);
        assertEquals(output.getChannelCount(), 1);
        Type type = operator.getTypes().get(0);

        Block block = output.getBlock(0);
        assertEquals(block.getPositionCount(), 1);

        return type.getObjectValue(session.toConnectorSession(), block, 0);
    }
View Full Code Here

            public Expression rewriteExpression(Expression node, Void context, ExpressionTreeRewriter<Void> treeRewriter)
            {
                Expression rewrittenExpression = treeRewriter.defaultRewrite(node, context);

                // cast expression if coercion is registered
                Type coercion = analysis.getCoercion(node);
                if (coercion != null) {
                    rewrittenExpression = new Cast(rewrittenExpression, coercion.getName());
                }

                return rewrittenExpression;
            }
        }, parsedExpression);
View Full Code Here

    /**
     * Produce a block with the given values in the last field.
     */
    private Block createBlock(List<Object> values)
    {
        Type type = getValueType();
        BlockBuilder blockBuilder = type.createBlockBuilder(new BlockBuilderStatus());

        for (Object value : values) {
            Class<?> javaType = type.getJavaType();
            if (value == null) {
                blockBuilder.appendNull();
            }
            else if (javaType == boolean.class) {
                type.writeBoolean(blockBuilder, (Boolean) value);
            }
            else if (javaType == long.class) {
                type.writeLong(blockBuilder, (Long) value);
            }
            else if (javaType == double.class) {
                type.writeDouble(blockBuilder, (Double) value);
            }
            else if (javaType == Slice.class) {
                Slice slice = (Slice) value;
                type.writeSlice(blockBuilder, slice, 0, slice.length());
            }
            else {
                throw new UnsupportedOperationException("not yet implemented: " + javaType);
            }
        }
View Full Code Here

                    columns.add(tableScanNode.getAssignments().get(symbol));

                    Input input = new Input(channel);
                    sourceLayout.put(symbol, input);

                    Type type = checkNotNull(context.getTypes().get(symbol), "No type for symbol %s", symbol);
                    sourceTypes.put(input, type);

                    channel++;
                }
            }
View Full Code Here

        private Map<Input, Type> getInputTypes(Map<Symbol, Input> layout, List<Type> types)
        {
            Builder<Input, Type> inputTypes = ImmutableMap.builder();
            for (Input input : ImmutableSet.copyOf(layout.values())) {
                Type type = types.get(input.getChannel());
                inputTypes.put(input, type);
            }
            return inputTypes.build();
        }
View Full Code Here

            int channel = 0;
            for (Symbol symbol : node.getOutputSymbols()) {
                Input input = new Input(channel);
                outputMappings.put(symbol, input);

                Type type = checkNotNull(context.getTypes().get(symbol), "No type for symbol %s", symbol);
                outputTypes.add(type);

                channel++;
            }
View Full Code Here

TOP

Related Classes of com.facebook.presto.spi.type.Type

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.