Search in sources :

Example 1 with DEFAULT_PRECISION

use of com.facebook.presto.testing.MaterializedResult.DEFAULT_PRECISION in project presto by prestodb.

the class TestCassandraIntegrationSmokeTest method assertSelect.

private void assertSelect(String tableName, boolean createdByPresto) {
    Type uuidType = createdByPresto ? createUnboundedVarcharType() : createVarcharType(36);
    Type inetType = createdByPresto ? createUnboundedVarcharType() : createVarcharType(45);
    String sql = "SELECT " + " key, " + " typeuuid, " + " typeinteger, " + " typelong, " + " typebytes, " + " typetimestamp, " + " typeansi, " + " typeboolean, " + " typedecimal, " + " typedouble, " + " typefloat, " + " typeinet, " + " typevarchar, " + " typevarint, " + " typetimeuuid, " + " typelist, " + " typemap, " + " typeset " + " FROM " + tableName;
    MaterializedResult result = execute(sql);
    int rowCount = result.getRowCount();
    assertEquals(rowCount, 9);
    assertEquals(result.getTypes(), ImmutableList.of(createUnboundedVarcharType(), uuidType, INTEGER, BIGINT, VARBINARY, TIMESTAMP, createUnboundedVarcharType(), BOOLEAN, DOUBLE, DOUBLE, REAL, inetType, createUnboundedVarcharType(), createUnboundedVarcharType(), uuidType, createUnboundedVarcharType(), createUnboundedVarcharType(), createUnboundedVarcharType()));
    List<MaterializedRow> sortedRows = result.getMaterializedRows().stream().sorted((o1, o2) -> o1.getField(1).toString().compareTo(o2.getField(1).toString())).collect(toList());
    for (int rowNumber = 1; rowNumber <= rowCount; rowNumber++) {
        assertEquals(sortedRows.get(rowNumber - 1), new MaterializedRow(DEFAULT_PRECISION, "key " + rowNumber, String.format("00000000-0000-0000-0000-%012d", rowNumber), rowNumber, rowNumber + 1000L, ByteBuffer.wrap(toByteArray(rowNumber)), TIMESTAMP_LOCAL, "ansi " + rowNumber, rowNumber % 2 == 0, Math.pow(2, rowNumber), Math.pow(4, rowNumber), (float) Math.pow(8, rowNumber), "127.0.0.1", "varchar " + rowNumber, BigInteger.TEN.pow(rowNumber).toString(), String.format("d2177dd0-eaa2-11de-a572-001b779c76e%d", rowNumber), String.format("[\"list-value-1%1$d\",\"list-value-2%1$d\"]", rowNumber), String.format("{%d:%d,%d:%d}", rowNumber, rowNumber + 1L, rowNumber + 2, rowNumber + 3L), "[false,true]"));
    }
}
Also used : DOUBLE(com.facebook.presto.spi.type.DoubleType.DOUBLE) Date(java.util.Date) TABLE_ALL_TYPES(com.facebook.presto.cassandra.CassandraTestingUtils.TABLE_ALL_TYPES) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) ByteBuffer(java.nio.ByteBuffer) BIGINT(com.facebook.presto.spi.type.BigintType.BIGINT) Bytes.toRawHexString(com.datastax.driver.core.utils.Bytes.toRawHexString) DEFAULT_PRECISION(com.facebook.presto.testing.MaterializedResult.DEFAULT_PRECISION) ImmutableList(com.google.common.collect.ImmutableList) BOOLEAN(com.facebook.presto.spi.type.BooleanType.BOOLEAN) Type(com.facebook.presto.spi.type.Type) TABLE_ALL_TYPES_PARTITION_KEY(com.facebook.presto.cassandra.CassandraTestingUtils.TABLE_ALL_TYPES_PARTITION_KEY) BigInteger(java.math.BigInteger) Ints.toByteArray(com.google.common.primitives.Ints.toByteArray) TIMESTAMP(com.facebook.presto.spi.type.TimestampType.TIMESTAMP) VARBINARY(com.facebook.presto.spi.type.VarbinaryType.VARBINARY) TABLE_CLUSTERING_KEYS_LARGE(com.facebook.presto.cassandra.CassandraTestingUtils.TABLE_CLUSTERING_KEYS_LARGE) Session(com.facebook.presto.Session) BeforeClass(org.testng.annotations.BeforeClass) Timestamp(java.sql.Timestamp) DateTime(org.joda.time.DateTime) TABLE_CLUSTERING_KEYS(com.facebook.presto.cassandra.CassandraTestingUtils.TABLE_CLUSTERING_KEYS) UTC(org.joda.time.DateTimeZone.UTC) CassandraQueryRunner.createCassandraSession(com.facebook.presto.cassandra.CassandraQueryRunner.createCassandraSession) CassandraTestingUtils.createTestTables(com.facebook.presto.cassandra.CassandraTestingUtils.createTestTables) VarcharType.createUnboundedVarcharType(com.facebook.presto.spi.type.VarcharType.createUnboundedVarcharType) MaterializedResult(com.facebook.presto.testing.MaterializedResult) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) REAL(com.facebook.presto.spi.type.RealType.REAL) VarcharType.createVarcharType(com.facebook.presto.spi.type.VarcharType.createVarcharType) MaterializedRow(com.facebook.presto.testing.MaterializedRow) TABLE_MULTI_PARTITION_CLUSTERING_KEYS(com.facebook.presto.cassandra.CassandraTestingUtils.TABLE_MULTI_PARTITION_CLUSTERING_KEYS) AbstractTestIntegrationSmokeTest(com.facebook.presto.tests.AbstractTestIntegrationSmokeTest) INTEGER(com.facebook.presto.spi.type.IntegerType.INTEGER) Type(com.facebook.presto.spi.type.Type) VarcharType.createUnboundedVarcharType(com.facebook.presto.spi.type.VarcharType.createUnboundedVarcharType) VarcharType.createVarcharType(com.facebook.presto.spi.type.VarcharType.createVarcharType) Bytes.toRawHexString(com.datastax.driver.core.utils.Bytes.toRawHexString) MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow)

Aggregations

Bytes.toRawHexString (com.datastax.driver.core.utils.Bytes.toRawHexString)1 Session (com.facebook.presto.Session)1 CassandraQueryRunner.createCassandraSession (com.facebook.presto.cassandra.CassandraQueryRunner.createCassandraSession)1 TABLE_ALL_TYPES (com.facebook.presto.cassandra.CassandraTestingUtils.TABLE_ALL_TYPES)1 TABLE_ALL_TYPES_PARTITION_KEY (com.facebook.presto.cassandra.CassandraTestingUtils.TABLE_ALL_TYPES_PARTITION_KEY)1 TABLE_CLUSTERING_KEYS (com.facebook.presto.cassandra.CassandraTestingUtils.TABLE_CLUSTERING_KEYS)1 TABLE_CLUSTERING_KEYS_LARGE (com.facebook.presto.cassandra.CassandraTestingUtils.TABLE_CLUSTERING_KEYS_LARGE)1 TABLE_MULTI_PARTITION_CLUSTERING_KEYS (com.facebook.presto.cassandra.CassandraTestingUtils.TABLE_MULTI_PARTITION_CLUSTERING_KEYS)1 CassandraTestingUtils.createTestTables (com.facebook.presto.cassandra.CassandraTestingUtils.createTestTables)1 BIGINT (com.facebook.presto.spi.type.BigintType.BIGINT)1 BOOLEAN (com.facebook.presto.spi.type.BooleanType.BOOLEAN)1 DOUBLE (com.facebook.presto.spi.type.DoubleType.DOUBLE)1 INTEGER (com.facebook.presto.spi.type.IntegerType.INTEGER)1 REAL (com.facebook.presto.spi.type.RealType.REAL)1 TIMESTAMP (com.facebook.presto.spi.type.TimestampType.TIMESTAMP)1 Type (com.facebook.presto.spi.type.Type)1 VARBINARY (com.facebook.presto.spi.type.VarbinaryType.VARBINARY)1 VarcharType.createUnboundedVarcharType (com.facebook.presto.spi.type.VarcharType.createUnboundedVarcharType)1 VarcharType.createVarcharType (com.facebook.presto.spi.type.VarcharType.createVarcharType)1 MaterializedResult (com.facebook.presto.testing.MaterializedResult)1