use of io.prestosql.Session in project hetu-core by openlookeng.
the class TestMySqlTypeMapping method testDate.
@Test
public void testDate() {
// Note: there is identical test for PostgreSQL
ZoneId jvmZone = ZoneId.systemDefault();
checkState(jvmZone.getId().equals("America/Bahia_Banderas"), "This test assumes certain JVM time zone");
LocalDate dateOfLocalTimeChangeForwardAtMidnightInJvmZone = LocalDate.of(1970, 1, 1);
verify(jvmZone.getRules().getValidOffsets(dateOfLocalTimeChangeForwardAtMidnightInJvmZone.atStartOfDay()).isEmpty());
ZoneId someZone = ZoneId.of("Europe/Vilnius");
LocalDate dateOfLocalTimeChangeForwardAtMidnightInSomeZone = LocalDate.of(1983, 4, 1);
verify(someZone.getRules().getValidOffsets(dateOfLocalTimeChangeForwardAtMidnightInSomeZone.atStartOfDay()).isEmpty());
LocalDate dateOfLocalTimeChangeBackwardAtMidnightInSomeZone = LocalDate.of(1983, 10, 1);
verify(someZone.getRules().getValidOffsets(dateOfLocalTimeChangeBackwardAtMidnightInSomeZone.atStartOfDay().minusMinutes(1)).size() == 2);
DataTypeTest testCases = DataTypeTest.create().addRoundTrip(dateDataType(), // before epoch
LocalDate.of(1952, 4, 3)).addRoundTrip(dateDataType(), LocalDate.of(1970, 1, 1)).addRoundTrip(dateDataType(), LocalDate.of(1970, 2, 3)).addRoundTrip(dateDataType(), // summer on northern hemisphere (possible DST)
LocalDate.of(2017, 7, 1)).addRoundTrip(dateDataType(), // winter on northern hemisphere (possible DST on southern hemisphere)
LocalDate.of(2017, 1, 1)).addRoundTrip(dateDataType(), dateOfLocalTimeChangeForwardAtMidnightInJvmZone).addRoundTrip(dateDataType(), dateOfLocalTimeChangeForwardAtMidnightInSomeZone).addRoundTrip(dateDataType(), dateOfLocalTimeChangeBackwardAtMidnightInSomeZone);
for (String timeZoneId : ImmutableList.of(UTC_KEY.getId(), jvmZone.getId(), someZone.getId())) {
Session session = Session.builder(getQueryRunner().getDefaultSession()).setTimeZoneKey(TimeZoneKey.getTimeZoneKey(timeZoneId)).build();
testCases.execute(getQueryRunner(), session, mysqlCreateAndInsert("tpch.test_date"));
testCases.execute(getQueryRunner(), session, prestoCreateAsSelect("test_date"));
}
}
use of io.prestosql.Session in project hetu-core by openlookeng.
the class TestMySqlIntegrationSmokeTest method floatingPointColumn.
@Test
public void floatingPointColumn() throws Exception {
Session session = testSessionBuilder().setCatalog("mysql").setSchema("test_database").build();
assertUpdate("CREATE TABLE mysql.test_database.testFloating(a real, b double)");
assertUpdate("INSERT INTO mysql.test_database.testFloating VALUES (1.987, 3.1487596)", 1);
assertQuery("SELECT * FROM mysql.test_database.testFloating", "SELECT 1.987 a, 3.1487596 b");
assertUpdate("DROP TABLE mysql.test_database.testFloating");
}
use of io.prestosql.Session in project hetu-core by openlookeng.
the class ThriftQueryRunner method createThriftQueryRunnerInternal.
private static DistributedQueryRunner createThriftQueryRunnerInternal(List<DriftServer> servers, int nodeCount, Map<String, String> properties) throws Exception {
String addresses = servers.stream().map(server -> "localhost:" + driftServerPort(server)).collect(joining(","));
Session defaultSession = testSessionBuilder().setCatalog("thrift").setSchema("tiny").build();
DistributedQueryRunner queryRunner = DistributedQueryRunner.builder(defaultSession).setNodeCount(nodeCount).setExtraProperties(properties).build();
queryRunner.installPlugin(new ThriftPlugin());
Map<String, String> connectorProperties = ImmutableMap.<String, String>builder().put("presto.thrift.client.addresses", addresses).put("presto.thrift.client.connect-timeout", "30s").put("presto-thrift.lookup-requests-concurrency", "2").build();
queryRunner.createCatalog("thrift", "presto-thrift", connectorProperties);
return queryRunner;
}
use of io.prestosql.Session in project hetu-core by openlookeng.
the class ValuesMatcher method detailMatches.
@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) {
checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
ValuesNode valuesNode = (ValuesNode) node;
if (!expectedRows.map(rows -> rows.equals(valuesNode.getRows().stream().map(rowExpressions -> rowExpressions.stream().map(rowExpression -> {
if (isExpression(rowExpression)) {
return castToExpression(rowExpression);
}
ConstantExpression expression = (ConstantExpression) rowExpression;
if (expression.getType().getJavaType() == boolean.class) {
return new BooleanLiteral(String.valueOf(expression.getValue()));
}
if (expression.getType().getJavaType() == long.class) {
return new LongLiteral(String.valueOf(expression.getValue()));
}
if (expression.getType().getJavaType() == double.class) {
return new DoubleLiteral(String.valueOf(expression.getValue()));
}
if (expression.getType().getJavaType() == Slice.class) {
return new StringLiteral(String.valueOf(expression.getValue()));
}
return new GenericLiteral(expression.getType().toString(), String.valueOf(expression.getValue()));
}).collect(toImmutableList())).collect(toImmutableList()))).orElse(true)) {
return NO_MATCH;
}
return match(SymbolAliases.builder().putAll(Maps.transformValues(outputSymbolAliases, index -> toSymbolReference(valuesNode.getOutputSymbols().get(index)))).build());
}
use of io.prestosql.Session in project hetu-core by openlookeng.
the class JoinMatcher method detailMatches.
@Override
public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) {
checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName());
JoinNode joinNode = (JoinNode) node;
if (joinNode.getCriteria().size() != equiCriteria.size()) {
return NO_MATCH;
}
if (filter.isPresent()) {
if (!joinNode.getFilter().isPresent()) {
return NO_MATCH;
}
RowExpression expression = joinNode.getFilter().get();
if (isExpression(expression)) {
if (!new ExpressionVerifier(symbolAliases).process(castToExpression(expression), filter.get())) {
return NO_MATCH;
}
} else {
if (!new RowExpressionVerifier(symbolAliases, metadata, session, node.getOutputSymbols()).process(filter.get(), expression)) {
return NO_MATCH;
}
}
} else {
if (joinNode.getFilter().isPresent()) {
return NO_MATCH;
}
}
if (distributionType.isPresent() && !distributionType.equals(joinNode.getDistributionType())) {
return NO_MATCH;
}
if (spillable.isPresent() && !spillable.equals(joinNode.isSpillable())) {
return NO_MATCH;
}
/*
* Have to use order-independent comparison; there are no guarantees what order
* the equi criteria will have after planning and optimizing.
*/
Set<JoinNode.EquiJoinClause> actual = ImmutableSet.copyOf(joinNode.getCriteria());
Set<JoinNode.EquiJoinClause> expected = equiCriteria.stream().map(maker -> maker.getExpectedValue(symbolAliases)).collect(toImmutableSet());
if (!expected.equals(actual)) {
return NO_MATCH;
}
if (dynamicFilter.isPresent() && !dynamicFilter.get().match(joinNode, symbolAliases).isMatch()) {
return NO_MATCH;
}
return MatchResult.match();
}
Aggregations