Search in sources :

Example 16 with SqlVarbinary

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

the class TestQuantileDigestAggregationFunction method getExpectedValuesFloats.

private Object getExpectedValuesFloats(double maxError, float... values) {
    if (values.length == 0) {
        return null;
    }
    QuantileDigest qdigest = new QuantileDigest(maxError);
    Floats.asList(values).forEach(value -> qdigest.add(floatToSortableInt(value)));
    return new SqlVarbinary(qdigest.serialize().getBytes());
}
Also used : QuantileDigest(io.airlift.stats.QuantileDigest) SqlVarbinary(io.prestosql.spi.type.SqlVarbinary)

Example 17 with SqlVarbinary

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

the class TestQuantileDigestAggregationFunction method testAggregationReal.

private void testAggregationReal(InternalAggregationFunction function, Page page, double maxError, float... inputs) {
    assertAggregation(function, QDIGEST_EQUALITY, "test multiple positions", page, getExpectedValuesFloats(maxError, inputs));
    // test scalars
    List<Double> rows = Floats.asList(inputs).stream().sorted().map(Float::doubleValue).collect(Collectors.toList());
    SqlVarbinary returned = (SqlVarbinary) AggregationTestUtils.aggregation(function, page);
    assertPercentileWithinError(StandardTypes.REAL, returned, maxError, rows, 0.1, 0.5, 0.9, 0.99);
}
Also used : SqlVarbinary(io.prestosql.spi.type.SqlVarbinary)

Example 18 with SqlVarbinary

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

the class TestQuantileDigestAggregationFunction method testAggregationBigints.

private void testAggregationBigints(InternalAggregationFunction function, Page page, double maxError, long... inputs) {
    // aggregate level
    assertAggregation(function, QDIGEST_EQUALITY, "test multiple positions", page, getExpectedValueLongs(maxError, inputs));
    // test scalars
    List<Long> rows = Arrays.stream(inputs).sorted().boxed().collect(Collectors.toList());
    SqlVarbinary returned = (SqlVarbinary) AggregationTestUtils.aggregation(function, page);
    assertPercentileWithinError(StandardTypes.BIGINT, returned, maxError, rows, 0.1, 0.5, 0.9, 0.99);
}
Also used : FloatingPointBitsConverterUtil.doubleToSortableLong(io.prestosql.operator.aggregation.FloatingPointBitsConverterUtil.doubleToSortableLong) SqlVarbinary(io.prestosql.spi.type.SqlVarbinary)

Example 19 with SqlVarbinary

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

the class TestQuantileDigestAggregationFunction method testAggregationDoubles.

private void testAggregationDoubles(InternalAggregationFunction function, Page page, double maxError, double... inputs) {
    assertAggregation(function, QDIGEST_EQUALITY, "test multiple positions", page, getExpectedValueDoubles(maxError, inputs));
    // test scalars
    List<Double> rows = Arrays.stream(inputs).sorted().boxed().collect(Collectors.toList());
    SqlVarbinary returned = (SqlVarbinary) AggregationTestUtils.aggregation(function, page);
    assertPercentileWithinError(StandardTypes.DOUBLE, returned, maxError, rows, 0.1, 0.5, 0.9, 0.99);
}
Also used : SqlVarbinary(io.prestosql.spi.type.SqlVarbinary)

Example 20 with SqlVarbinary

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

the class TestStringFunctions method testReverse.

@Test
public void testReverse() {
    assertFunction("REVERSE('')", createVarcharType(0), "");
    assertFunction("REVERSE('hello')", createVarcharType(5), "olleh");
    assertFunction("REVERSE('Quadratically')", createVarcharType(13), "yllacitardauQ");
    assertFunction("REVERSE('racecar')", createVarcharType(7), "racecar");
    // Test REVERSE for non-ASCII
    assertFunction("REVERSE('\u4FE1\u5FF5,\u7231,\u5E0C\u671B')", createVarcharType(7), "\u671B\u5E0C,\u7231,\u5FF5\u4FE1");
    assertFunction("REVERSE('\u00D6sterreich')", createVarcharType(10), "hcierrets\u00D6");
    assertFunction("REVERSE('na\u00EFve')", createVarcharType(5), "ev\u00EFan");
    assertFunction("REVERSE('\uD801\uDC2Dend')", createVarcharType(4), "dne\uD801\uDC2D");
    assertFunction("CAST(REVERSE(utf8(from_hex('CE'))) AS VARBINARY)", VARBINARY, new SqlVarbinary(new byte[] { (byte) 0xCE }));
    assertFunction("CAST(REVERSE('hello' || utf8(from_hex('CE'))) AS VARBINARY)", VARBINARY, new SqlVarbinary(new byte[] { (byte) 0xCE, 'o', 'l', 'l', 'e', 'h' }));
}
Also used : SqlVarbinary(io.prestosql.spi.type.SqlVarbinary) Test(org.testng.annotations.Test)

Aggregations

SqlVarbinary (io.prestosql.spi.type.SqlVarbinary)28 DecimalType (io.prestosql.spi.type.DecimalType)10 SqlDate (io.prestosql.spi.type.SqlDate)10 SqlTimestamp (io.prestosql.spi.type.SqlTimestamp)10 ImmutableList (com.google.common.collect.ImmutableList)9 SqlDecimal (io.prestosql.spi.type.SqlDecimal)9 List (java.util.List)9 Type (io.prestosql.spi.type.Type)8 Collectors.toList (java.util.stream.Collectors.toList)8 Test (org.testng.annotations.Test)8 Slice (io.airlift.slice.Slice)6 BlockBuilder (io.prestosql.spi.block.BlockBuilder)6 CharType (io.prestosql.spi.type.CharType)6 ArrayList (java.util.ArrayList)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)5 VarcharType (io.prestosql.spi.type.VarcharType)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)3