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 906D7200B4A for ; Wed, 20 Jul 2016 20:54:01 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 8ECDA160A64; Wed, 20 Jul 2016 18:54: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 D6E9F160A5B for ; Wed, 20 Jul 2016 20:54:00 +0200 (CEST) Received: (qmail 36379 invoked by uid 500); 20 Jul 2016 18:54:00 -0000 Mailing-List: contact dev-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 dev@drill.apache.org Received: (qmail 36367 invoked by uid 99); 20 Jul 2016 18:53:59 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Jul 2016 18:53:59 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 892D4E04BA; Wed, 20 Jul 2016 18:53:59 +0000 (UTC) From: vdiravka To: dev@drill.apache.org Reply-To: dev@drill.apache.org References: In-Reply-To: Subject: [GitHub] drill pull request #541: DRILL-4673: Implement "DROP TABLE IF EXISTS" for dr... Content-Type: text/plain Message-Id: <20160720185359.892D4E04BA@git1-us-west.apache.org> Date: Wed, 20 Jul 2016 18:53:59 +0000 (UTC) archived-at: Wed, 20 Jul 2016 18:54:01 -0000 Github user vdiravka commented on a diff in the pull request: https://github.com/apache/drill/pull/541#discussion_r71585003 --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/DropTableIfExistsHandler.java --- @@ -28,47 +30,57 @@ import org.apache.drill.exec.physical.PhysicalPlan; import org.apache.drill.exec.planner.sql.DirectPlan; import org.apache.drill.exec.planner.sql.SchemaUtilites; -import org.apache.drill.exec.planner.sql.parser.SqlDropTable; +import org.apache.drill.exec.planner.sql.parser.SqlDropTableIfExists; import org.apache.drill.exec.store.AbstractSchema; // SqlHandler for dropping a table. -public class DropTableHandler extends DefaultSqlHandler { +public class DropTableIfExistsHandler extends DefaultSqlHandler { - private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DropTableHandler.class); + private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(DropTableIfExistsHandler.class); - public DropTableHandler(SqlHandlerConfig config) { + public DropTableIfExistsHandler(SqlHandlerConfig config) { super(config); } /** - * Function resolves the schema and invokes the drop method. Raises an exception if the schema is - * immutable. - * @param sqlNode - Table name identifier - * @return - Single row indicating drop succeeded, raise exception otherwise + * Function resolves the schema and invokes the drop method + * (while IF EXISTS statement is used function invokes the drop method only if table exists). + * Raises an exception if the schema is immutable. + * @param sqlNode - SqlDropTableIfExists (SQL parse tree of drop table [if exists] query) + * @return - Single row indicating drop succeeded or table is not found while IF EXISTS statement is used, + * raise exception otherwise * @throws ValidationException * @throws RelConversionException * @throws IOException */ @Override public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, RelConversionException, IOException { - SqlDropTable dropTableNode = ((SqlDropTable) sqlNode); - SqlIdentifier tableIdentifier = dropTableNode.getTableIdentifier(); + SqlDropTableIfExists dropTableIfExistsNode = ((SqlDropTableIfExists) sqlNode); + SqlIdentifier tableIdentifier = dropTableIfExistsNode.getTableIdentifier(); SchemaPlus defaultSchema = config.getConverter().getDefaultSchema(); AbstractSchema drillSchema = null; if (tableIdentifier != null) { - drillSchema = SchemaUtilites.resolveToMutableDrillSchema(defaultSchema, dropTableNode.getSchema()); + drillSchema = SchemaUtilites.resolveToMutableDrillSchema(defaultSchema, dropTableIfExistsNode.getSchema()); } - String tableName = ((SqlDropTable) sqlNode).getName(); + String tableName = dropTableIfExistsNode.getName(); if (drillSchema == null) { throw UserException.validationError() .message("Invalid table_name [%s]", tableName) .build(logger); } + if (dropTableIfExistsNode.checkTableExistence()) { + final Table tableToDrop = SqlHandlerUtil.getTableFromSchema(drillSchema, tableName); + if (tableToDrop == null || tableToDrop.getJdbcTableType() != Schema.TableType.TABLE) { --- End diff -- I checked such query `drop table if exists hbase.TestTableNullStr` and found that the message is proper and same like for `DROP TABLE` statement: `PARSE ERROR: Unable to create or drop tables/views. Schema [hbase] is immutable.`. --- 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. ---