Github user arina-ielchiieva commented on a diff in the pull request:

    https://github.com/apache/drill/pull/666#discussion_r94757849
  
    --- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/SqlConverter.java
 ---
    @@ -447,4 +458,50 @@ public RexNode ensureType(
           return node;
         }
       }
    +
    +  /**
    +   * Extension of {@link CalciteCatalogReader} to add ability to check for 
temporary tables first
    +   * if schema is not indicated near table name during query parsing
    +   * or indicated workspace is default temporary workspace.
    +   */
    +  private class DrillCalciteCatalogReader extends CalciteCatalogReader {
    +
    +    private final String temporarySchema;
    +    private final UserSession session;
    +
    +    DrillCalciteCatalogReader(CalciteSchema rootSchema,
    +                                     boolean caseSensitive,
    +                                     List<String> defaultSchema,
    +                                     JavaTypeFactory typeFactory,
    +                                     String temporarySchema,
    +                                     UserSession session) {
    +      super(rootSchema, caseSensitive, defaultSchema, typeFactory);
    +      this.temporarySchema = temporarySchema;
    +      this.session = session;
    +    }
    +
    +    /**
    +     * If schema is not indicated (only one element in the list) or schema 
is default temporary workspace,
    +     * we need to check among session temporary tables first in default 
temporary workspace.
    +     * If temporary table is found, its table instance will be returned,
    +     * otherwise search will be conducted in original workspace.
    +     *
    +     * @param names list of schema and table names, table name is always 
the last element
    +     * @return table instance, null otherwise
    +     */
    +    @Override
    +    public RelOptTableImpl getTable(final List<String> names) {
    +      RelOptTableImpl foundTemporaryTable = null;
    +      String schemaPath = SchemaUtilites.getSchemaPath(names.subList(0, 
names.size() - 1));
    +      if (names.size() == 1 || schemaPath.equals(temporarySchema)) {
    +        String temporaryTable = 
session.findTemporaryTable(names.get(names.size() - 1));
    +        if (temporaryTable != null) {
    +          List<String> temporaryNames = 
Lists.newArrayList(temporarySchema);
    +          temporaryNames.add(temporaryTable);
    --- End diff --
    
    Done, thanks!


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to