Search in sources :

Example 6 with DOUBLE

use of io.prestosql.spi.type.DoubleType.DOUBLE in project hetu-core by openlookeng.

the class ElasticsearchMetadata method toPrestoType.

private Type toPrestoType(IndexMetadata.Field metaDataField, boolean isArray) {
    IndexMetadata.Type type = metaDataField.getType();
    if (isArray) {
        Type elementType = toPrestoType(metaDataField, false);
        return new ArrayType(elementType);
    }
    if (type instanceof PrimitiveType) {
        switch(((PrimitiveType) type).getName()) {
            case "float":
                return REAL;
            case "double":
                return DOUBLE;
            case "byte":
                return TINYINT;
            case "short":
                return SMALLINT;
            case "integer":
                return INTEGER;
            case "long":
                return BIGINT;
            case "string":
            case "text":
            case "keyword":
                return VARCHAR;
            case "ip":
                return ipAddressType;
            case "boolean":
                return BOOLEAN;
            case "binary":
                return VARBINARY;
            default:
                break;
        }
    } else if (type instanceof DateTimeType) {
        if (((DateTimeType) type).getFormats().isEmpty()) {
            return TIMESTAMP;
        }
    // otherwise, skip -- we don't support custom formats, yet
    } else if (type instanceof ObjectType) {
        ObjectType objectType = (ObjectType) type;
        List<RowType.Field> fields = objectType.getFields().stream().map(field -> RowType.field(field.getName(), toPrestoType(field))).collect(toImmutableList());
        return RowType.from(fields);
    }
    return null;
}
Also used : ArrayType(io.prestosql.spi.type.ArrayType) ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata) StandardTypes(io.prestosql.spi.type.StandardTypes) INTEGER(io.prestosql.spi.type.IntegerType.INTEGER) DateTimeType(io.prestosql.elasticsearch.client.IndexMetadata.DateTimeType) PrimitiveType(io.prestosql.elasticsearch.client.IndexMetadata.PrimitiveType) Inject(javax.inject.Inject) ObjectType(io.prestosql.elasticsearch.client.IndexMetadata.ObjectType) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) VARCHAR(io.prestosql.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) IndexMetadata(io.prestosql.elasticsearch.client.IndexMetadata) ConnectorTableProperties(io.prestosql.spi.connector.ConnectorTableProperties) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) RowType(io.prestosql.spi.type.RowType) BOOLEAN(io.prestosql.spi.type.BooleanType.BOOLEAN) DOUBLE(io.prestosql.spi.type.DoubleType.DOUBLE) Type(io.prestosql.spi.type.Type) REAL(io.prestosql.spi.type.RealType.REAL) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) ENGLISH(java.util.Locale.ENGLISH) Constraint(io.prestosql.spi.connector.Constraint) ConstraintApplicationResult(io.prestosql.spi.connector.ConstraintApplicationResult) ImmutableMap(com.google.common.collect.ImmutableMap) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) TupleDomain(io.prestosql.spi.predicate.TupleDomain) ArrayType(io.prestosql.spi.type.ArrayType) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) TypeManager(io.prestosql.spi.type.TypeManager) TIMESTAMP(io.prestosql.spi.type.TimestampType.TIMESTAMP) TINYINT(io.prestosql.spi.type.TinyintType.TINYINT) Collectors(java.util.stream.Collectors) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) VARBINARY(io.prestosql.spi.type.VarbinaryType.VARBINARY) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) SMALLINT(io.prestosql.spi.type.SmallintType.SMALLINT) Optional(java.util.Optional) TypeSignature(io.prestosql.spi.type.TypeSignature) SchemaTablePrefix(io.prestosql.spi.connector.SchemaTablePrefix) ObjectType(io.prestosql.elasticsearch.client.IndexMetadata.ObjectType) DateTimeType(io.prestosql.elasticsearch.client.IndexMetadata.DateTimeType) PrimitiveType(io.prestosql.elasticsearch.client.IndexMetadata.PrimitiveType) ObjectType(io.prestosql.elasticsearch.client.IndexMetadata.ObjectType) RowType(io.prestosql.spi.type.RowType) Type(io.prestosql.spi.type.Type) ArrayType(io.prestosql.spi.type.ArrayType) DateTimeType(io.prestosql.elasticsearch.client.IndexMetadata.DateTimeType) PrimitiveType(io.prestosql.elasticsearch.client.IndexMetadata.PrimitiveType) IndexMetadata(io.prestosql.elasticsearch.client.IndexMetadata)

Example 7 with DOUBLE

use of io.prestosql.spi.type.DoubleType.DOUBLE in project hetu-core by openlookeng.

the class AbstractTestHiveFileFormats method checkCursor.

protected void checkCursor(RecordCursor cursor, List<TestColumn> testColumns, int rowCount) {
    List<Type> types = testColumns.stream().map(column -> column.getObjectInspector().getTypeName()).map(type -> HiveType.valueOf(type).getType(TYPE_MANAGER)).collect(toImmutableList());
    Map<Type, MethodHandle> distinctFromOperators = types.stream().distinct().collect(toImmutableMap(identity(), HiveTestUtils::distinctFromOperator));
    for (int row = 0; row < rowCount; row++) {
        assertTrue(cursor.advanceNextPosition());
        for (int i = 0, testColumnsSize = testColumns.size(); i < testColumnsSize; i++) {
            TestColumn testColumn = testColumns.get(i);
            Type type = types.get(i);
            Object fieldFromCursor = getFieldFromCursor(cursor, type, i);
            if (fieldFromCursor == null) {
                assertEquals(null, testColumn.getExpectedValue(), "Expected null for column " + testColumn.getName());
            } else if (type instanceof DecimalType) {
                DecimalType decimalType = (DecimalType) type;
                fieldFromCursor = new BigDecimal((BigInteger) fieldFromCursor, decimalType.getScale());
                assertEquals(fieldFromCursor, testColumn.getExpectedValue(), "Wrong value for column " + testColumn.getName());
            } else if (testColumn.getObjectInspector().getTypeName().equals("float")) {
                assertEquals((float) fieldFromCursor, (float) testColumn.getExpectedValue(), (float) EPSILON);
            } else if (testColumn.getObjectInspector().getTypeName().equals("double")) {
                assertEquals((double) fieldFromCursor, (double) testColumn.getExpectedValue(), EPSILON);
            } else if (testColumn.getObjectInspector().getTypeName().equals("tinyint")) {
                assertEquals(((Number) fieldFromCursor).byteValue(), testColumn.getExpectedValue());
            } else if (testColumn.getObjectInspector().getTypeName().equals("smallint")) {
                assertEquals(((Number) fieldFromCursor).shortValue(), testColumn.getExpectedValue());
            } else if (testColumn.getObjectInspector().getTypeName().equals("int")) {
                assertEquals(((Number) fieldFromCursor).intValue(), testColumn.getExpectedValue());
            } else if (testColumn.getObjectInspector().getCategory() == Category.PRIMITIVE) {
                assertEquals(fieldFromCursor, testColumn.getExpectedValue(), "Wrong value for column " + testColumn.getName());
            } else {
                Block expected = (Block) testColumn.getExpectedValue();
                Block actual = (Block) fieldFromCursor;
                boolean distinct = isDistinctFrom(distinctFromOperators.get(type), expected, actual);
                assertFalse(distinct, "Wrong value for column: " + testColumn.getName());
            }
        }
    }
    assertFalse(cursor.advanceNextPosition());
}
Also used : DateTimeZone(org.joda.time.DateTimeZone) Arrays(java.util.Arrays) StorageFormat(io.prestosql.plugin.hive.metastore.StorageFormat) JavaHiveDecimalObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaHiveDecimalObjectInspector) PrimitiveObjectInspectorFactory.javaByteObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaByteObjectInspector) Text(org.apache.hadoop.io.Text) PrimitiveObjectInspectorFactory.javaLongObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaLongObjectInspector) Writable(org.apache.hadoop.io.Writable) Test(org.testng.annotations.Test) PrimitiveObjectInspectorFactory.javaTimestampObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaTimestampObjectInspector) Date(org.apache.hadoop.hive.common.type.Date) HiveTestUtils.isDistinctFrom(io.prestosql.plugin.hive.HiveTestUtils.isDistinctFrom) PrimitiveObjectInspectorFactory.javaDateObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaDateObjectInspector) HiveChar(org.apache.hadoop.hive.common.type.HiveChar) BigDecimal(java.math.BigDecimal) FileSplit(org.apache.hadoop.mapred.FileSplit) Predicates.not(com.google.common.base.Predicates.not) Slices(io.airlift.slice.Slices) Configuration(org.apache.hadoop.conf.Configuration) Map(java.util.Map) RowType(io.prestosql.spi.type.RowType) BigInteger(java.math.BigInteger) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) Assert.assertFalse(org.testng.Assert.assertFalse) Chars.isCharType(io.prestosql.spi.type.Chars.isCharType) PrimitiveObjectInspectorFactory.javaByteArrayObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaByteArrayObjectInspector) PrimitiveObjectInspectorFactory.javaFloatObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaFloatObjectInspector) PrimitiveObjectInspectorFactory.javaDoubleObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaDoubleObjectInspector) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) PrimitiveObjectInspectorFactory.javaHiveVarcharObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaHiveVarcharObjectInspector) VarcharType.createVarcharType(io.prestosql.spi.type.VarcharType.createVarcharType) TimestampType(io.prestosql.spi.type.TimestampType) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) StructuralTestUtil.mapBlockOf(io.prestosql.tests.StructuralTestUtil.mapBlockOf) ConnectorPageSource(io.prestosql.spi.connector.ConnectorPageSource) Iterables.filter(com.google.common.collect.Iterables.filter) StructuralTestUtil.decimalMapBlockOf(io.prestosql.tests.StructuralTestUtil.decimalMapBlockOf) PrimitiveObjectInspectorFactory.javaIntObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaIntObjectInspector) Joiner(com.google.common.base.Joiner) StructField(org.apache.hadoop.hive.serde2.objectinspector.StructField) JavaHiveCharObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.JavaHiveCharObjectInspector) MethodHandle(java.lang.invoke.MethodHandle) Slice(io.airlift.slice.Slice) TYPE_MANAGER(io.prestosql.plugin.hive.HiveTestUtils.TYPE_MANAGER) StructuralTestUtil.decimalArrayBlockOf(io.prestosql.tests.StructuralTestUtil.decimalArrayBlockOf) CharType(io.prestosql.spi.type.CharType) StructuralTestUtil.rowBlockOf(io.prestosql.tests.StructuralTestUtil.rowBlockOf) ArrayList(java.util.ArrayList) REGULAR(io.prestosql.plugin.hive.HiveColumnHandle.ColumnType.REGULAR) PrimitiveObjectInspectorFactory.javaShortObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaShortObjectInspector) PARTITION_KEY(io.prestosql.plugin.hive.HiveColumnHandle.ColumnType.PARTITION_KEY) DOUBLE(io.prestosql.spi.type.DoubleType.DOUBLE) RecordCursor(io.prestosql.spi.connector.RecordCursor) StructuralTestUtil(io.prestosql.tests.StructuralTestUtil) SESSION(io.prestosql.plugin.hive.HiveTestUtils.SESSION) HiveTestUtils.mapType(io.prestosql.plugin.hive.HiveTestUtils.mapType) Arrays.fill(java.util.Arrays.fill) Properties(java.util.Properties) IOException(java.io.IOException) ObjectInspectorFactory.getStandardStructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory.getStandardStructObjectInspector) UTC(org.joda.time.DateTimeZone.UTC) MaterializedRow(io.prestosql.testing.MaterializedRow) DecimalTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo) File(java.io.File) SettableStructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.SettableStructObjectInspector) VARBINARY(io.prestosql.spi.type.VarbinaryType.VARBINARY) DateTimeTestingUtils.sqlTimestampOf(io.prestosql.testing.DateTimeTestingUtils.sqlTimestampOf) HIVE_DEFAULT_DYNAMIC_PARTITION(io.prestosql.plugin.hive.HivePartitionKey.HIVE_DEFAULT_DYNAMIC_PARTITION) RecordWriter(org.apache.hadoop.hive.ql.exec.FileSinkOperator.RecordWriter) Varchars.isVarcharType(io.prestosql.spi.type.Varchars.isVarcharType) Iterables.transform(com.google.common.collect.Iterables.transform) DecimalType(io.prestosql.spi.type.DecimalType) MaterializedResult.materializeSourceDataStream(io.prestosql.testing.MaterializedResult.materializeSourceDataStream) MaterializedResult(io.prestosql.testing.MaterializedResult) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) Path(org.apache.hadoop.fs.Path) BOOLEAN(io.prestosql.spi.type.BooleanType.BOOLEAN) Type(io.prestosql.spi.type.Type) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) DateTimeFormat(org.joda.time.format.DateTimeFormat) ImmutableMap(com.google.common.collect.ImmutableMap) BlockBuilder(io.prestosql.spi.block.BlockBuilder) ArrayType(io.prestosql.spi.type.ArrayType) CharType.createCharType(io.prestosql.spi.type.CharType.createCharType) TINYINT(io.prestosql.spi.type.TinyintType.TINYINT) HiveOutputFormat(org.apache.hadoop.hive.ql.io.HiveOutputFormat) PageBuilder(io.prestosql.spi.PageBuilder) List(java.util.List) VarcharType.createUnboundedVarcharType(io.prestosql.spi.type.VarcharType.createUnboundedVarcharType) Function.identity(java.util.function.Function.identity) Optional(java.util.Optional) TypeInfoFactory.getCharTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory.getCharTypeInfo) SqlTimestamp(io.prestosql.spi.type.SqlTimestamp) Strings.padEnd(com.google.common.base.Strings.padEnd) HiveUtil.isStructuralType(io.prestosql.plugin.hive.HiveUtil.isStructuralType) PrimitiveObjectInspectorFactory.javaBooleanObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaBooleanObjectInspector) SqlDate(io.prestosql.spi.type.SqlDate) SerDeUtils.serializeObject(io.prestosql.plugin.hive.util.SerDeUtils.serializeObject) Assert.assertEquals(org.testng.Assert.assertEquals) Decimals(io.prestosql.spi.type.Decimals) HashMap(java.util.HashMap) INTEGER(io.prestosql.spi.type.IntegerType.INTEGER) SqlDecimal(io.prestosql.spi.type.SqlDecimal) HdfsConfigurationInitializer.configureCompression(io.prestosql.plugin.hive.HdfsConfigurationInitializer.configureCompression) Float.intBitsToFloat(java.lang.Float.intBitsToFloat) SqlVarbinary(io.prestosql.spi.type.SqlVarbinary) Category(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category) HiveVarchar(org.apache.hadoop.hive.common.type.HiveVarchar) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) REAL(io.prestosql.spi.type.RealType.REAL) ObjectInspectorFactory.getStandardMapObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory.getStandardMapObjectInspector) Block(io.prestosql.spi.block.Block) Timestamp(org.apache.hadoop.hive.common.type.Timestamp) UTF_8(java.nio.charset.StandardCharsets.UTF_8) DateTime(org.joda.time.DateTime) Page(io.prestosql.spi.Page) ObjectInspectorFactory.getStandardListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspectorFactory.getStandardListObjectInspector) JobConf(org.apache.hadoop.mapred.JobConf) TimeUnit(java.util.concurrent.TimeUnit) Collectors.toList(java.util.stream.Collectors.toList) SMALLINT(io.prestosql.spi.type.SmallintType.SMALLINT) DateType(io.prestosql.spi.type.DateType) Serializer(org.apache.hadoop.hive.serde2.Serializer) HiveDecimal(org.apache.hadoop.hive.common.type.HiveDecimal) StructuralTestUtil.arrayBlockOf(io.prestosql.tests.StructuralTestUtil.arrayBlockOf) Assert.assertTrue(org.testng.Assert.assertTrue) PrimitiveObjectInspectorFactory.javaStringObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory.javaStringObjectInspector) RowType(io.prestosql.spi.type.RowType) Chars.isCharType(io.prestosql.spi.type.Chars.isCharType) VarcharType.createVarcharType(io.prestosql.spi.type.VarcharType.createVarcharType) TimestampType(io.prestosql.spi.type.TimestampType) CharType(io.prestosql.spi.type.CharType) HiveTestUtils.mapType(io.prestosql.plugin.hive.HiveTestUtils.mapType) Varchars.isVarcharType(io.prestosql.spi.type.Varchars.isVarcharType) DecimalType(io.prestosql.spi.type.DecimalType) Type(io.prestosql.spi.type.Type) ArrayType(io.prestosql.spi.type.ArrayType) CharType.createCharType(io.prestosql.spi.type.CharType.createCharType) VarcharType.createUnboundedVarcharType(io.prestosql.spi.type.VarcharType.createUnboundedVarcharType) HiveUtil.isStructuralType(io.prestosql.plugin.hive.HiveUtil.isStructuralType) DateType(io.prestosql.spi.type.DateType) DecimalType(io.prestosql.spi.type.DecimalType) Block(io.prestosql.spi.block.Block) SerDeUtils.serializeObject(io.prestosql.plugin.hive.util.SerDeUtils.serializeObject) BigDecimal(java.math.BigDecimal) MethodHandle(java.lang.invoke.MethodHandle)

Example 8 with DOUBLE

use of io.prestosql.spi.type.DoubleType.DOUBLE in project hetu-core by openlookeng.

the class TestValuesNodeStats method testStatsForValuesNode.

@Test
public void testStatsForValuesNode() {
    tester().assertStatsFor(pb -> pb.values(ImmutableList.of(pb.symbol("a", BIGINT), pb.symbol("b", DOUBLE)), ImmutableList.of(ImmutableList.of(pb.binaryOperation(OperatorType.ADD, constant(3L, BIGINT), constant(3L, BIGINT)), constant(13.5e0, DOUBLE)), ImmutableList.of(constant(55L, BIGINT), constantNull(DOUBLE)), ImmutableList.of(constant(6L, BIGINT), constant(13.5e0, DOUBLE))))).check(outputStats -> outputStats.equalTo(PlanNodeStatsEstimate.builder().setOutputRowCount(3).addSymbolStatistics(new Symbol("a"), SymbolStatsEstimate.builder().setNullsFraction(0).setLowValue(6).setHighValue(55).setDistinctValuesCount(2).build()).addSymbolStatistics(new Symbol("b"), SymbolStatsEstimate.builder().setNullsFraction(0.33333333333333333).setLowValue(13.5).setHighValue(13.5).setDistinctValuesCount(1).build()).build()));
    tester().assertStatsFor(pb -> pb.values(ImmutableList.of(pb.symbol("v", createVarcharType(30))), ImmutableList.of(constantExpressions(VARCHAR, utf8Slice("Alice")), constantExpressions(VARCHAR, utf8Slice("has")), constantExpressions(VARCHAR, utf8Slice("a cat")), ImmutableList.of(constantNull(VARCHAR))))).check(outputStats -> outputStats.equalTo(PlanNodeStatsEstimate.builder().setOutputRowCount(4).addSymbolStatistics(new Symbol("v"), SymbolStatsEstimate.builder().setNullsFraction(0.25).setDistinctValuesCount(3).build()).build()));
}
Also used : Symbol(io.prestosql.spi.plan.Symbol) PlanBuilder.constantExpressions(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder.constantExpressions) Expressions.constant(io.prestosql.sql.relational.Expressions.constant) Test(org.testng.annotations.Test) Expressions.constantNull(io.prestosql.sql.relational.Expressions.constantNull) VarcharType.createVarcharType(io.prestosql.spi.type.VarcharType.createVarcharType) VARCHAR(io.prestosql.spi.type.VarcharType.VARCHAR) ImmutableList(com.google.common.collect.ImmutableList) OperatorType(io.prestosql.spi.function.OperatorType) DOUBLE(io.prestosql.spi.type.DoubleType.DOUBLE) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) UNKNOWN(io.prestosql.spi.type.UnknownType.UNKNOWN) Symbol(io.prestosql.spi.plan.Symbol) Test(org.testng.annotations.Test)

Example 9 with DOUBLE

use of io.prestosql.spi.type.DoubleType.DOUBLE in project hetu-core by openlookeng.

the class TestJoinStatsRule method testStatsForInnerJoinWithTwoEquiClausesAndNonEqualityFunction.

@Test
public void testStatsForInnerJoinWithTwoEquiClausesAndNonEqualityFunction() {
    double innerJoinRowCount = // driver join clause
    LEFT_ROWS_COUNT * RIGHT_ROWS_COUNT / LEFT_JOIN_COLUMN_2_NDV * LEFT_JOIN_COLUMN_2_NON_NULLS * RIGHT_JOIN_COLUMN_2_NON_NULLS * // auxiliary join clause
    UNKNOWN_FILTER_COEFFICIENT * // LEFT_JOIN_COLUMN < 10 non equality filter
    0.3333333333;
    PlanNodeStatsEstimate innerJoinStats = planNodeStats(innerJoinRowCount, symbolStatistics(LEFT_JOIN_COLUMN, 5.0, 10.0, 0.0, RIGHT_JOIN_COLUMN_NDV * 0.3333333333), symbolStatistics(RIGHT_JOIN_COLUMN, 5.0, 20.0, 0.0, RIGHT_JOIN_COLUMN_NDV), symbolStatistics(LEFT_JOIN_COLUMN_2, 100.0, 200.0, 0.0, RIGHT_JOIN_COLUMN_2_NDV), symbolStatistics(RIGHT_JOIN_COLUMN_2, 100.0, 200.0, 0.0, RIGHT_JOIN_COLUMN_2_NDV));
    tester().assertStatsFor(pb -> {
        Symbol leftJoinColumnSymbol = pb.symbol(LEFT_JOIN_COLUMN, BIGINT);
        Symbol rightJoinColumnSymbol = pb.symbol(RIGHT_JOIN_COLUMN, DOUBLE);
        Symbol leftJoinColumnSymbol2 = pb.symbol(LEFT_JOIN_COLUMN_2, BIGINT);
        Symbol rightJoinColumnSymbol2 = pb.symbol(RIGHT_JOIN_COLUMN_2, DOUBLE);
        ComparisonExpression leftJoinColumnLessThanTen = new ComparisonExpression(ComparisonExpression.Operator.LESS_THAN, toSymbolReference(leftJoinColumnSymbol), new LongLiteral("10"));
        return pb.join(INNER, pb.values(leftJoinColumnSymbol, leftJoinColumnSymbol2), pb.values(rightJoinColumnSymbol, rightJoinColumnSymbol2), ImmutableList.of(new EquiJoinClause(leftJoinColumnSymbol2, rightJoinColumnSymbol2), new EquiJoinClause(leftJoinColumnSymbol, rightJoinColumnSymbol)), ImmutableList.of(leftJoinColumnSymbol, leftJoinColumnSymbol2, rightJoinColumnSymbol, rightJoinColumnSymbol2), Optional.of(castToRowExpression(leftJoinColumnLessThanTen)));
    }).withSourceStats(0, planNodeStats(LEFT_ROWS_COUNT, LEFT_JOIN_COLUMN_STATS, LEFT_JOIN_COLUMN_2_STATS)).withSourceStats(1, planNodeStats(RIGHT_ROWS_COUNT, RIGHT_JOIN_COLUMN_STATS, RIGHT_JOIN_COLUMN_2_STATS)).check(stats -> stats.equalTo(innerJoinStats));
}
Also used : EquiJoinClause(io.prestosql.spi.plan.JoinNode.EquiJoinClause) TypeProvider(io.prestosql.sql.planner.TypeProvider) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) PlanNodeStatsAssertion.assertThat(io.prestosql.cost.PlanNodeStatsAssertion.assertThat) ImmutableList(com.google.common.collect.ImmutableList) NaN(java.lang.Double.NaN) OriginalExpressionUtils.castToRowExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToRowExpression) DOUBLE(io.prestosql.spi.type.DoubleType.DOUBLE) Type(io.prestosql.spi.type.Type) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) JoinNode(io.prestosql.spi.plan.JoinNode) Symbol(io.prestosql.spi.plan.Symbol) UNKNOWN_FILTER_COEFFICIENT(io.prestosql.cost.FilterStatsCalculator.UNKNOWN_FILTER_COEFFICIENT) ImmutableMap(com.google.common.collect.ImmutableMap) FULL(io.prestosql.spi.plan.JoinNode.Type.FULL) MetadataManager.createTestMetadataManager(io.prestosql.metadata.MetadataManager.createTestMetadataManager) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) Metadata(io.prestosql.metadata.Metadata) SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) RIGHT(io.prestosql.spi.plan.JoinNode.Type.RIGHT) LongLiteral(io.prestosql.sql.tree.LongLiteral) INNER(io.prestosql.spi.plan.JoinNode.Type.INNER) Optional(java.util.Optional) LEFT(io.prestosql.spi.plan.JoinNode.Type.LEFT) ComparisonExpression(io.prestosql.sql.tree.ComparisonExpression) LongLiteral(io.prestosql.sql.tree.LongLiteral) Symbol(io.prestosql.spi.plan.Symbol) EquiJoinClause(io.prestosql.spi.plan.JoinNode.EquiJoinClause) Test(org.testng.annotations.Test)

Example 10 with DOUBLE

use of io.prestosql.spi.type.DoubleType.DOUBLE in project hetu-core by openlookeng.

the class TestSortStatsRule method testStatsForSortNode.

@Test
public void testStatsForSortNode() {
    PlanNodeStatsEstimate stats = PlanNodeStatsEstimate.builder().setOutputRowCount(100).addSymbolStatistics(new Symbol("a"), SymbolStatsEstimate.builder().setNullsFraction(0.3).setLowValue(1).setHighValue(30).setDistinctValuesCount(20).build()).addSymbolStatistics(new Symbol("b"), SymbolStatsEstimate.builder().setNullsFraction(0.6).setLowValue(13.5).setHighValue(POSITIVE_INFINITY).setDistinctValuesCount(40).build()).build();
    tester().assertStatsFor(pb -> pb.output(outputBuilder -> {
        Symbol a = pb.symbol("a", BIGINT);
        Symbol b = pb.symbol("b", DOUBLE);
        outputBuilder.source(pb.values(a, b)).column(a, "a1").column(a, "a2").column(b, "b");
    })).withSourceStats(stats).check(outputStats -> outputStats.equalTo(stats));
}
Also used : Symbol(io.prestosql.spi.plan.Symbol) POSITIVE_INFINITY(java.lang.Double.POSITIVE_INFINITY) DOUBLE(io.prestosql.spi.type.DoubleType.DOUBLE) Test(org.testng.annotations.Test) BIGINT(io.prestosql.spi.type.BigintType.BIGINT) Symbol(io.prestosql.spi.plan.Symbol) Test(org.testng.annotations.Test)

Aggregations

DOUBLE (io.prestosql.spi.type.DoubleType.DOUBLE)28 BIGINT (io.prestosql.spi.type.BigintType.BIGINT)25 List (java.util.List)22 Optional (java.util.Optional)22 Type (io.prestosql.spi.type.Type)21 ImmutableMap (com.google.common.collect.ImmutableMap)20 ImmutableList (com.google.common.collect.ImmutableList)19 INTEGER (io.prestosql.spi.type.IntegerType.INTEGER)19 ArrayList (java.util.ArrayList)16 Map (java.util.Map)15 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)14 SMALLINT (io.prestosql.spi.type.SmallintType.SMALLINT)14 String.format (java.lang.String.format)14 Test (org.testng.annotations.Test)14 Slice (io.airlift.slice.Slice)13 DATE (io.prestosql.spi.type.DateType.DATE)13 TINYINT (io.prestosql.spi.type.TinyintType.TINYINT)13 DecimalType (io.prestosql.spi.type.DecimalType)12 REAL (io.prestosql.spi.type.RealType.REAL)12 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)11