Search in sources :

Example 11 with Session

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"));
    }
}
Also used : DataTypeTest(io.prestosql.tests.datatype.DataTypeTest) ZoneId(java.time.ZoneId) LocalDate(java.time.LocalDate) Session(io.prestosql.Session) Test(org.testng.annotations.Test) DataTypeTest(io.prestosql.tests.datatype.DataTypeTest)

Example 12 with Session

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");
}
Also used : Session(io.prestosql.Session) Test(org.testng.annotations.Test) AbstractTestIntegrationSmokeTest(io.prestosql.tests.AbstractTestIntegrationSmokeTest)

Example 13 with Session

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;
}
Also used : NullMethodInvocationStatsFactory(io.airlift.drift.server.stats.NullMethodInvocationStatsFactory) NodePartitioningManager(io.prestosql.sql.planner.NodePartitioningManager) Plugin(io.prestosql.spi.Plugin) Logger(io.airlift.log.Logger) TransactionManager(io.prestosql.transaction.TransactionManager) DriftService(io.airlift.drift.server.DriftService) MaterializedResult(io.prestosql.testing.MaterializedResult) QualifiedObjectName(io.prestosql.spi.connector.QualifiedObjectName) ArrayList(java.util.ArrayList) TestingSession.testSessionBuilder(io.prestosql.testing.TestingSession.testSessionBuilder) TestingAccessControlManager(io.prestosql.testing.TestingAccessControlManager) ConnectorPlanOptimizerManager(io.prestosql.sql.planner.ConnectorPlanOptimizerManager) ImmutableList(com.google.common.collect.ImmutableList) DriftNettyServerConfig(io.airlift.drift.transport.netty.server.DriftNettyServerConfig) ThriftIndexedTpchService(io.prestosql.plugin.thrift.server.ThriftIndexedTpchService) DistributedQueryRunner(io.prestosql.tests.DistributedQueryRunner) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Logging(io.airlift.log.Logging) Session(io.prestosql.Session) PageSourceManager(io.prestosql.split.PageSourceManager) StatsCalculator(io.prestosql.cost.StatsCalculator) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Closeables.closeQuietly(io.airlift.testing.Closeables.closeQuietly) ThriftPlugin(io.prestosql.plugin.thrift.ThriftPlugin) QueryRunner(io.prestosql.testing.QueryRunner) DriftServer(io.airlift.drift.server.DriftServer) TestingPrestoServer(io.prestosql.server.testing.TestingPrestoServer) Metadata(io.prestosql.metadata.Metadata) Collectors.joining(java.util.stream.Collectors.joining) ThriftCodecManager(io.airlift.drift.codec.ThriftCodecManager) List(java.util.List) Lock(java.util.concurrent.locks.Lock) ThriftTpchService(io.prestosql.plugin.thrift.server.ThriftTpchService) SplitManager(io.prestosql.split.SplitManager) DriftNettyServerTransportFactory(io.airlift.drift.transport.netty.server.DriftNettyServerTransportFactory) DriftNettyServerTransport(io.airlift.drift.transport.netty.server.DriftNettyServerTransport) DistributedQueryRunner(io.prestosql.tests.DistributedQueryRunner) ThriftPlugin(io.prestosql.plugin.thrift.ThriftPlugin) Session(io.prestosql.Session)

Example 14 with Session

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());
}
Also used : Slice(io.airlift.slice.Slice) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) OriginalExpressionUtils.isExpression(io.prestosql.sql.relational.OriginalExpressionUtils.isExpression) BooleanLiteral(io.prestosql.sql.tree.BooleanLiteral) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) OriginalExpressionUtils.castToExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression) NO_MATCH(io.prestosql.sql.planner.assertions.MatchResult.NO_MATCH) StatsProvider(io.prestosql.cost.StatsProvider) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) MatchResult.match(io.prestosql.sql.planner.assertions.MatchResult.match) PlanNode(io.prestosql.spi.plan.PlanNode) Maps(com.google.common.collect.Maps) Metadata(io.prestosql.metadata.Metadata) Preconditions.checkState(com.google.common.base.Preconditions.checkState) SymbolUtils.toSymbolReference(io.prestosql.sql.planner.SymbolUtils.toSymbolReference) ValuesNode(io.prestosql.spi.plan.ValuesNode) List(java.util.List) DoubleLiteral(io.prestosql.sql.tree.DoubleLiteral) GenericLiteral(io.prestosql.sql.tree.GenericLiteral) LongLiteral(io.prestosql.sql.tree.LongLiteral) StringLiteral(io.prestosql.sql.tree.StringLiteral) Optional(java.util.Optional) Expression(io.prestosql.sql.tree.Expression) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) ValuesNode(io.prestosql.spi.plan.ValuesNode) StringLiteral(io.prestosql.sql.tree.StringLiteral) LongLiteral(io.prestosql.sql.tree.LongLiteral) BooleanLiteral(io.prestosql.sql.tree.BooleanLiteral) Slice(io.airlift.slice.Slice) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) DoubleLiteral(io.prestosql.sql.tree.DoubleLiteral) GenericLiteral(io.prestosql.sql.tree.GenericLiteral)

Example 15 with Session

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();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) StatsProvider(io.prestosql.cost.StatsProvider) Set(java.util.Set) PlanNode(io.prestosql.spi.plan.PlanNode) Metadata(io.prestosql.metadata.Metadata) Preconditions.checkState(com.google.common.base.Preconditions.checkState) OriginalExpressionUtils.isExpression(io.prestosql.sql.relational.OriginalExpressionUtils.isExpression) List(java.util.List) DistributionType(io.prestosql.spi.plan.JoinNode.DistributionType) Objects.requireNonNull(java.util.Objects.requireNonNull) Session(io.prestosql.Session) RowExpression(io.prestosql.spi.relation.RowExpression) Optional(java.util.Optional) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) OriginalExpressionUtils.castToExpression(io.prestosql.sql.relational.OriginalExpressionUtils.castToExpression) NO_MATCH(io.prestosql.sql.planner.assertions.MatchResult.NO_MATCH) Expression(io.prestosql.sql.tree.Expression) JoinNode(io.prestosql.spi.plan.JoinNode) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) JoinNode(io.prestosql.spi.plan.JoinNode) RowExpression(io.prestosql.spi.relation.RowExpression)

Aggregations

Session (io.prestosql.Session)281 Test (org.testng.annotations.Test)147 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)54 List (java.util.List)53 Optional (java.util.Optional)51 MaterializedResult (io.prestosql.testing.MaterializedResult)47 Metadata (io.prestosql.metadata.Metadata)44 QualifiedObjectName (io.prestosql.spi.connector.QualifiedObjectName)44 Map (java.util.Map)44 Objects.requireNonNull (java.util.Objects.requireNonNull)40 TableHandle (io.prestosql.spi.metadata.TableHandle)34 PrestoException (io.prestosql.spi.PrestoException)32 ImmutableList (com.google.common.collect.ImmutableList)31 Type (io.prestosql.spi.type.Type)31 Set (java.util.Set)31 ImmutableMap (com.google.common.collect.ImmutableMap)30 HashMap (java.util.HashMap)30 HeuristicIndexerManager (io.prestosql.heuristicindex.HeuristicIndexerManager)28 AbstractTestIntegrationSmokeTest (io.prestosql.tests.AbstractTestIntegrationSmokeTest)28 ImmutableSet (com.google.common.collect.ImmutableSet)27