drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paul-rogers <...@git.apache.org>
Subject [GitHub] drill pull request #666: DRILL-4956: Temporary tables support
Date Thu, 05 Jan 2017 02:34:21 GMT
Github user paul-rogers commented on a diff in the pull request:

    https://github.com/apache/drill/pull/666#discussion_r94704798
  
    --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ViewHandler.java
---
    @@ -74,36 +74,51 @@ public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException,
RelConv
           final SchemaPlus defaultSchema = context.getNewDefaultSchema();
           final AbstractSchema drillSchema = SchemaUtilites.resolveToMutableDrillSchema(defaultSchema,
createView.getSchemaPath());
     
    -      final String schemaPath = drillSchema.getFullSchemaName();
           final View view = new View(newViewName, viewSql, newViewRelNode.getRowType(),
               SchemaUtilites.getSchemaPathAsList(defaultSchema));
     
    -      final Table existingTable = SqlHandlerUtil.getTableFromSchema(drillSchema, newViewName);
    +      validateViewCreationPossibility(drillSchema, newViewName, createView.getReplace());
    +
    +      final boolean replaced = drillSchema.createView(view);
    +      final String summary = String.format("View '%s' %s successfully in '%s' schema",
    +          createView.getName(), replaced ? "replaced" : "created", drillSchema.getFullSchemaName());
    +
    +      return DirectPlan.createDirectPlan(context, true, summary);
    +    }
    +
    +    /**
    +     * Validates if view can be created in indicated schema:
    +     * checks if object (persistent / temporary table) with the same exists
    +     * in indicated schema, or if view exists but replace flag is not set.
    +     *
    +     * @param drillSchema schema where views will be created
    +     * @param viewName view name
    +     * @param replaceView replace view if exists
    +     * @throws UserException if views can be created in indicated schema
    +     */
    +    private void validateViewCreationPossibility(AbstractSchema drillSchema, String viewName,
boolean replaceView) {
    --- End diff --
    
    So what happens?
    
    ```
    CREATE TEMPORARY TABLE foo AS ...
    CREATE VIEW bar AS SELECT * FROM foo;
    ```
    Logout. Log back in:
    ```
    SELECT * FROM bar;
    ```
    The above fails, right?
    ```
    CREATE TEMPORARY TABLE foo AS ...
    SELECT * FROM bar;
    ```
    Does this now succeed? If so, this raises another issue:
    ```
    USE `my-schema`; // contains table foo
    CREATE VIEW bar AS SELECT * FROM foo;
    SELECT * FROM bar;
    ```
    This selects data from `my-schema.foo`. Fine.
    ```
    CREATE TEMPORARY TABLE foo AS ...
    SELECT * FROM bar;
    ```
    Does the existing view bar now resolve to the temp table `foo`? Or, does it remember that
it used to resolve to the prior `my-schema.foo`?
    
    This seems like a usability hole. It is one thing to change the meaning of
    ```
    SELECT * FROM foo;
    ```
    After I create a temp table of the same name: clearly I saw table names and knew what
I was doing. But, table names in views are hidden.
    
    So, is a solution to forbid the use of temporary tables in creating views?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message