[ https://issues.apache.org/jira/browse/DRILL-4956?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15800064#comment-15800064 ]
ASF GitHub Bot commented on DRILL-4956: --------------------------------------- Github user paul-rogers commented on a diff in the pull request: https://github.com/apache/drill/pull/666#discussion_r94690087 --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/CreateTableHandler.java --- @@ -242,4 +267,53 @@ private RexNode composeDisjunction(final RexBuilder rexBuilder, List<RexNode> co return node; } + /** + * Gets schema path defined in create table statement. + * If temporary table is being created and schema is not indicated, + * uses default temporary workspace. + * + * @param sqlCreateTable create table call + * @param temporaryWorkspace default temporary workspace + * @return table schema path + */ + private List<String> getSchemaPath(SqlCreateTable sqlCreateTable, String temporaryWorkspace) { + List<String> indicatedSchemaPath = sqlCreateTable.getSchemaPath(); + if (sqlCreateTable.isTemporary() && indicatedSchemaPath.size() == 0) { + indicatedSchemaPath = Lists.newArrayList(temporaryWorkspace); + } + return indicatedSchemaPath; + } + + /** + * Checks if any object (persistent table / temporary table / view) + * with the same name as table to be created exists in indicated schema. + * + * @param drillSchema schema where table will be created + * @param tableName table name + * @param isTemporaryWorkspace is default temporary workspace + * @param userSession current user session + * @throws UserException if duplicate is found + */ + private void checkDuplicatedObjectExistence(AbstractSchema drillSchema, + String tableName, + boolean isTemporaryWorkspace, + UserSession userSession) { + String schemaPath = drillSchema.getFullSchemaName(); + boolean isTemporaryTable = false; + if (isTemporaryWorkspace) { + String temporaryTableName = userSession.findTemporaryTable(tableName); + if (temporaryTableName != null) { + Table temporaryTable = SqlHandlerUtil.getTableFromSchema(drillSchema, temporaryTableName); --- End diff -- Question here about concurrency. Suppose I kick of two queries from the same Drillbit connection, both of which do: ``` CREATE TEMPORARY TABLE foo AS ... ``` Both queries run at the same time. The first creates table foo in the user session temp table registry. The second finds the table and returns true from this function, then proceeds to overwrite the table as the first query runs. Is this possible? Do we register the new temp table only after the query completes? Or, before the query starts? If at start, do we need to worry about the race condition just outlined? > Temporary tables support > ------------------------ > > Key: DRILL-4956 > URL: https://issues.apache.org/jira/browse/DRILL-4956 > Project: Apache Drill > Issue Type: Improvement > Affects Versions: 1.8.0 > Reporter: Arina Ielchiieva > Assignee: Arina Ielchiieva > Labels: doc-impacting > Fix For: Future > > > Link to design doc - > https://docs.google.com/document/d/1gSRo_w6q2WR5fPx7SsQ5IaVmJXJ6xCOJfYGyqpVOC-g/edit -- This message was sent by Atlassian JIRA (v6.3.4#6332)