Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 9DCF1200C01 for ; Thu, 5 Jan 2017 03:35:01 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 9C8F4160B44; Thu, 5 Jan 2017 02:35:01 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 49586160B52 for ; Thu, 5 Jan 2017 03:35:00 +0100 (CET) Received: (qmail 55728 invoked by uid 500); 5 Jan 2017 02:34:59 -0000 Mailing-List: contact issues-help@drill.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@drill.apache.org Delivered-To: mailing list issues@drill.apache.org Received: (qmail 55546 invoked by uid 99); 5 Jan 2017 02:34:59 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Jan 2017 02:34:59 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 16B092C2ACF for ; Thu, 5 Jan 2017 02:34:59 +0000 (UTC) Date: Thu, 5 Jan 2017 02:34:59 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: issues@drill.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (DRILL-4956) Temporary tables support MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Thu, 05 Jan 2017 02:35:01 -0000 [ https://issues.apache.org/jira/browse/DRILL-4956?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15800074#comment-15800074 ] 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_r94704095 --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/DropTableHandler.java --- @@ -55,35 +58,79 @@ public DropTableHandler(SqlHandlerConfig config) { */ @Override public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, RelConversionException, IOException { - SqlDropTable dropTableNode = ((SqlDropTable) sqlNode); - SqlIdentifier tableIdentifier = dropTableNode.getTableIdentifier(); - + String originalTableName = dropTableNode.getName(); SchemaPlus defaultSchema = config.getConverter().getDefaultSchema(); - AbstractSchema drillSchema = null; + List tableSchema = dropTableNode.getSchema(); + + boolean removedTemporaryTable = removeTemporaryTable(defaultSchema, tableSchema, originalTableName); + // if table to be dropped is not temporary table, we need to check among persistent tables or views + if (!removedTemporaryTable) { + AbstractSchema drillSchema = SchemaUtilites.resolveToMutableDrillSchema(defaultSchema, tableSchema); + Table tableToDrop = SqlHandlerUtil.getTableFromSchema(drillSchema, originalTableName); + if (tableToDrop == null || tableToDrop.getJdbcTableType() != Schema.TableType.TABLE) { + if (dropTableNode.checkTableExistence()) { + return DirectPlan.createDirectPlan(context, false, String.format("Table [%s] not found", originalTableName)); + } else { + throw UserException.validationError().message("Table [%s] not found", originalTableName).build(logger); + } + } - if (tableIdentifier != null) { - drillSchema = SchemaUtilites.resolveToMutableDrillSchema(defaultSchema, dropTableNode.getSchema()); + try { + drillSchema.dropTable(originalTableName); + } catch (Exception e) { + // concurrency check: we might have failed because somebody has already dropped the table + if (SqlHandlerUtil.getTableFromSchema(drillSchema, originalTableName) != null) { + throw e; + } + } } - String tableName = dropTableNode.getName(); - if (drillSchema == null) { - throw UserException.validationError() - .message("Invalid table_name [%s]", tableName) - .build(logger); + String message = String.format("%s [%s] dropped", + removedTemporaryTable ? "Temporary table" : "Table", originalTableName); + logger.info(message); + return DirectPlan.createDirectPlan(context, true, message); + } + + /** + * If used workspace is default temporary workspace and temporary table is found, + * drops the table and removes it from session temporary tables list. + * + * @param defaultSchema default schema + * @param tableSchema table schema indicated in drop statement + * @param tableName table name to drop + * @return true if temporary table existed and was dropped, false otherwise + */ + private boolean removeTemporaryTable(SchemaPlus defaultSchema, List tableSchema, String tableName) { + String temporaryWorkspace = context.getConfig().getString(ExecConstants.DEFAULT_TEMPORARY_WORKSPACE); + + // look for temporary table only if default temporary workspace is used + if (!(tableSchema.isEmpty() || SchemaUtilites.getSchemaPath(tableSchema).equals(temporaryWorkspace))) { + return false; } - if (dropTableNode.checkTableExistence()) { - final Table tableToDrop = SqlHandlerUtil.getTableFromSchema(drillSchema, tableName); - if (tableToDrop == null || tableToDrop.getJdbcTableType() != Schema.TableType.TABLE) { - return DirectPlan.createDirectPlan(context, true, - String.format("Table [%s] not found", tableName)); - } + String temporaryTable = context.getSession().findTemporaryTable(tableName); + if (temporaryTable == null) { + return false; } - drillSchema.dropTable(tableName); + AbstractSchema drillSchema = SchemaUtilites.resolveToMutableDrillSchema(defaultSchema, + Lists.newArrayList(temporaryWorkspace)); - return DirectPlan.createDirectPlan(context, true, - String.format("Table [%s] %s", tableName, "dropped")); + Table tableToDrop = SqlHandlerUtil.getTableFromSchema(drillSchema, temporaryTable); + if (tableToDrop != null && tableToDrop.getJdbcTableType() == Schema.TableType.TABLE) { --- End diff -- This logic looks very similar to that earlier for non-temp tables. Can it be factored out? > 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)