trinodb / trino

Official repository of Trino, the distributed SQL query engine for big data, formerly known as PrestoSQL (https://trino.io)
https://trino.io
Apache License 2.0
10.28k stars 2.96k forks source link

CREATE TABLE AS SELECT WITH NO DATA can fail with "connector does not support creating tables with data" #3172

Open findepi opened 4 years ago

findepi commented 4 years ago
  1. Have a connector which supports creating tables (io.prestosql.spi.connector.ConnectorMetadata#createTable), but not creating tables with data (io.prestosql.spi.connector.ConnectorMetadata#beginCreateTable).
  2. Run CREATE TABLE new_table AS SELECT * FROM tpch.tiny.nation WITH NO DATA

Currently this fails with:

Query 20200320_101505_00001_hc6iv failed: This connector does not support creating tables with data
io.prestosql.spi.PrestoException: This connector does not support creating tables with data
    at io.prestosql.spi.connector.ConnectorMetadata.beginCreateTable(ConnectorMetadata.java:389)
    at io.prestosql.plugin.base.classloader.ClassLoaderSafeConnectorMetadata.beginCreateTable(ClassLoaderSafeConnectorMetadata.java:365)
    at io.prestosql.metadata.MetadataManager.beginCreateTable(MetadataManager.java:772)
    at io.prestosql.sql.planner.optimizations.BeginTableWrite$Rewriter.createWriterTarget(BeginTableWrite.java:179)
    at io.prestosql.sql.planner.optimizations.BeginTableWrite$Rewriter.visitTableFinish(BeginTableWrite.java:142)
    at io.prestosql.sql.planner.optimizations.BeginTableWrite$Rewriter.visitTableFinish(BeginTableWrite.java:76)
    at io.prestosql.sql.planner.plan.TableFinishNode.accept(TableFinishNode.java:106)
    at io.prestosql.sql.planner.plan.SimplePlanRewriter$RewriteContext.rewrite(SimplePlanRewriter.java:84)
    at io.prestosql.sql.planner.plan.SimplePlanRewriter$RewriteContext.lambda$defaultRewrite$0(SimplePlanRewriter.java:73)

-- the exception message ("... with data") is confusing, since user explicitly asked to create table WITHOUT data.

wendigo commented 4 years ago

So this should create table as connector supports this?

findepi commented 4 years ago

Yes, the expected behavior from my POV is that beginCreateTable() should not be called, and createTable should be called instead.

cc @kokosing @martint

electrum commented 4 years ago

Sounds good to me. I think the current implementation in the engine is a hack that needs to be fixed.

kokosing commented 4 years ago

The thing is that this query should not run any sql query execution. It should be a DDL task. All we care is the output schema of query, so output from analysis should be enough.