Search in sources :

Example 11 with SqlVarbinary

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

the class TestStringFunctions method testUpper.

@Test
public void testUpper() {
    assertFunction("UPPER('')", createVarcharType(0), "");
    assertFunction("UPPER('Hello World')", createVarcharType(11), "HELLO WORLD");
    assertFunction("UPPER('what!!')", createVarcharType(6), "WHAT!!");
    assertFunction("UPPER('\u00D6sterreich')", createVarcharType(10), upperByCodePoint("\u00D6") + "STERREICH");
    assertFunction("UPPER('From\uD801\uDC2DTo')", createVarcharType(7), "FROM" + upperByCodePoint("\uD801\uDC2D") + "TO");
    assertFunction("CAST(UPPER(utf8(from_hex('CE'))) AS VARBINARY)", VARBINARY, new SqlVarbinary(new byte[] { (byte) 0xCE }));
    assertFunction("CAST(UPPER('hello' || utf8(from_hex('CE'))) AS VARBINARY)", VARBINARY, new SqlVarbinary(new byte[] { 'H', 'E', 'L', 'L', 'O', (byte) 0xCE }));
    assertFunction("CAST(UPPER(utf8(from_hex('CE')) || 'hello') AS VARBINARY)", VARBINARY, new SqlVarbinary(new byte[] { (byte) 0xCE, 'H', 'E', 'L', 'L', 'O' }));
}
Also used : SqlVarbinary(io.prestosql.spi.type.SqlVarbinary) Test(org.testng.annotations.Test)

Example 12 with SqlVarbinary

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

the class TestMergeHyperLogLogAggregation method getExpectedValue.

@Override
protected Object getExpectedValue(int start, int length) {
    if (length == 0) {
        return null;
    }
    HyperLogLog hll = HyperLogLog.newInstance(NUMBER_OF_BUCKETS);
    for (int i = start; i < start + length; i++) {
        hll.add(i);
    }
    hll.makeDense();
    return new SqlVarbinary(hll.serialize().getBytes());
}
Also used : SqlVarbinary(io.prestosql.spi.type.SqlVarbinary) HyperLogLog(io.airlift.stats.cardinality.HyperLogLog)

Example 13 with SqlVarbinary

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

the class TestQuantileDigestAggregationFunction method getExpectedValueDoubles.

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

Example 14 with SqlVarbinary

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

the class TestQuantileDigestAggregationFunction method getExpectedValueLongs.

private Object getExpectedValueLongs(double maxError, long... values) {
    if (values.length == 0) {
        return null;
    }
    QuantileDigest qdigest = new QuantileDigest(maxError);
    Arrays.stream(values).forEach(qdigest::add);
    return new SqlVarbinary(qdigest.serialize().getBytes());
}
Also used : QuantileDigest(io.airlift.stats.QuantileDigest) SqlVarbinary(io.prestosql.spi.type.SqlVarbinary)

Example 15 with SqlVarbinary

use of io.prestosql.spi.type.SqlVarbinary in project boostkit-bigdata by kunpengcompute.

the class AbstractTestHive method assertGetRecords.

protected void assertGetRecords(HiveStorageFormat hiveStorageFormat, ConnectorTableMetadata tableMetadata, HiveSplit hiveSplit, ConnectorPageSource pageSource, List<? extends ColumnHandle> columnHandles) throws IOException {
    try {
        MaterializedResult result = materializeSourceDataStream(newSession(), pageSource, getTypes(columnHandles));
        assertPageSourceType(pageSource, hiveStorageFormat);
        ImmutableMap<String, Integer> columnIndex = indexColumns(tableMetadata);
        long rowNumber = 0;
        long completedBytes = 0;
        for (MaterializedRow row : result) {
            try {
                assertValueTypes(row, tableMetadata.getColumns());
            } catch (RuntimeException e) {
                throw new RuntimeException("row " + rowNumber, e);
            }
            rowNumber++;
            Integer index;
            Object value;
            // STRING
            index = columnIndex.get("t_string");
            value = row.getField(index);
            if (rowNumber % 19 == 0) {
                assertNull(value);
            } else if (rowNumber % 19 == 1) {
                assertEquals(value, "");
            } else {
                assertEquals(value, "test");
            }
            // NUMBERS
            assertEquals(row.getField(columnIndex.get("t_tinyint")), (byte) (1 + rowNumber));
            assertEquals(row.getField(columnIndex.get("t_smallint")), (short) (2 + rowNumber));
            assertEquals(row.getField(columnIndex.get("t_int")), (int) (3 + rowNumber));
            index = columnIndex.get("t_bigint");
            if ((rowNumber % 13) == 0) {
                assertNull(row.getField(index));
            } else {
                assertEquals(row.getField(index), 4 + rowNumber);
            }
            assertEquals((Float) row.getField(columnIndex.get("t_float")), 5.1f + rowNumber, 0.001);
            assertEquals(row.getField(columnIndex.get("t_double")), 6.2 + rowNumber);
            // BOOLEAN
            index = columnIndex.get("t_boolean");
            if ((rowNumber % 3) == 2) {
                assertNull(row.getField(index));
            } else {
                assertEquals(row.getField(index), (rowNumber % 3) != 0);
            }
            // TIMESTAMP
            index = columnIndex.get("t_timestamp");
            if (index != null) {
                if ((rowNumber % 17) == 0) {
                    assertNull(row.getField(index));
                } else {
                    SqlTimestamp expected = sqlTimestampOf(2011, 5, 6, 7, 8, 9, 123);
                    assertEquals(row.getField(index), expected);
                }
            }
            // BINARY
            index = columnIndex.get("t_binary");
            if (index != null) {
                if ((rowNumber % 23) == 0) {
                    assertNull(row.getField(index));
                } else {
                    assertEquals(row.getField(index), new SqlVarbinary("test binary".getBytes(UTF_8)));
                }
            }
            // DATE
            index = columnIndex.get("t_date");
            if (index != null) {
                if ((rowNumber % 37) == 0) {
                    assertNull(row.getField(index));
                } else {
                    SqlDate expected = new SqlDate(toIntExact(MILLISECONDS.toDays(new DateTime(2013, 8, 9, 0, 0, 0, UTC).getMillis())));
                    assertEquals(row.getField(index), expected);
                }
            }
            // VARCHAR(50)
            index = columnIndex.get("t_varchar");
            if (index != null) {
                value = row.getField(index);
                if (rowNumber % 39 == 0) {
                    assertNull(value);
                } else if (rowNumber % 39 == 1) {
                    // RCBINARY reads empty VARCHAR as null
                    if (hiveStorageFormat == RCBINARY) {
                        assertNull(value);
                    } else {
                        assertEquals(value, "");
                    }
                } else {
                    assertEquals(value, "test varchar");
                }
            }
            // CHAR(25)
            index = columnIndex.get("t_char");
            if (index != null) {
                value = row.getField(index);
                if ((rowNumber % 41) == 0) {
                    assertNull(value);
                } else {
                    assertEquals(value, (rowNumber % 41) == 1 ? "                         " : "test char                ");
                }
            }
            // MAP<STRING, STRING>
            index = columnIndex.get("t_map");
            if (index != null) {
                if ((rowNumber % 27) == 0) {
                    assertNull(row.getField(index));
                } else {
                    assertEquals(row.getField(index), ImmutableMap.of("test key", "test value"));
                }
            }
            // ARRAY<STRING>
            index = columnIndex.get("t_array_string");
            if (index != null) {
                if ((rowNumber % 29) == 0) {
                    assertNull(row.getField(index));
                } else {
                    assertEquals(row.getField(index), ImmutableList.of("abc", "xyz", "data"));
                }
            }
            // ARRAY<TIMESTAMP>
            index = columnIndex.get("t_array_timestamp");
            if (index != null) {
                if ((rowNumber % 43) == 0) {
                    assertNull(row.getField(index));
                } else {
                    SqlTimestamp expected = sqlTimestampOf(LocalDateTime.of(2011, 5, 6, 7, 8, 9, 123_000_000));
                    assertEquals(row.getField(index), ImmutableList.of(expected));
                }
            }
            // ARRAY<STRUCT<s_string: STRING, s_double:DOUBLE>>
            index = columnIndex.get("t_array_struct");
            if (index != null) {
                if ((rowNumber % 31) == 0) {
                    assertNull(row.getField(index));
                } else {
                    List<Object> expected1 = ImmutableList.of("test abc", 0.1);
                    List<Object> expected2 = ImmutableList.of("test xyz", 0.2);
                    assertEquals(row.getField(index), ImmutableList.of(expected1, expected2));
                }
            }
            // STRUCT<s_string: STRING, s_double:DOUBLE>
            index = columnIndex.get("t_struct");
            if (index != null) {
                if ((rowNumber % 31) == 0) {
                    assertNull(row.getField(index));
                } else {
                    assertTrue(row.getField(index) instanceof List);
                    List<?> values = (List<?>) row.getField(index);
                    assertEquals(values.size(), 2);
                    assertEquals(values.get(0), "test abc");
                    assertEquals(values.get(1), 0.1);
                }
            }
            // MAP<INT, ARRAY<STRUCT<s_string: STRING, s_double:DOUBLE>>>
            index = columnIndex.get("t_complex");
            if (index != null) {
                if ((rowNumber % 33) == 0) {
                    assertNull(row.getField(index));
                } else {
                    List<Object> expected1 = ImmutableList.of("test abc", 0.1);
                    List<Object> expected2 = ImmutableList.of("test xyz", 0.2);
                    assertEquals(row.getField(index), ImmutableMap.of(1, ImmutableList.of(expected1, expected2)));
                }
            }
            // NEW COLUMN
            assertNull(row.getField(columnIndex.get("new_column")));
            long newCompletedBytes = pageSource.getCompletedBytes();
            assertTrue(newCompletedBytes >= completedBytes);
            assertTrue(newCompletedBytes <= hiveSplit.getLength());
            completedBytes = newCompletedBytes;
        }
        assertTrue(completedBytes <= hiveSplit.getLength());
        assertEquals(rowNumber, 100);
    } finally {
        pageSource.close();
    }
}
Also used : SqlVarbinary(io.prestosql.spi.type.SqlVarbinary) SqlTimestamp(io.prestosql.spi.type.SqlTimestamp) LocalDateTime(java.time.LocalDateTime) DateTime(org.joda.time.DateTime) SqlDate(io.prestosql.spi.type.SqlDate) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) MaterializedResult(io.prestosql.testing.MaterializedResult) MaterializedRow(io.prestosql.testing.MaterializedRow)

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