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 05943200D54 for ; Fri, 24 Nov 2017 06:49:22 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 03F14160C10; Fri, 24 Nov 2017 05:49:22 +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 49D81160BFE for ; Fri, 24 Nov 2017 06:49:21 +0100 (CET) Received: (qmail 16154 invoked by uid 500); 24 Nov 2017 05:49:20 -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 16142 invoked by uid 99); 24 Nov 2017 05:49:20 -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; Fri, 24 Nov 2017 05:49:20 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D9BCFDFB86; Fri, 24 Nov 2017 05:49:19 +0000 (UTC) From: prasadns14 To: dev@drill.apache.org Reply-To: dev@drill.apache.org References: In-Reply-To: Subject: [GitHub] drill pull request #1033: DRILL-5952: Implement "CREATE TABLE IF NOT EXISTS" Content-Type: text/plain Message-Id: <20171124054919.D9BCFDFB86@git1-us-west.apache.org> Date: Fri, 24 Nov 2017 05:49:19 +0000 (UTC) archived-at: Fri, 24 Nov 2017 05:49:22 -0000 Github user prasadns14 commented on a diff in the pull request: https://github.com/apache/drill/pull/1033#discussion_r152900976 --- Diff: exec/java-exec/src/test/java/org/apache/drill/exec/sql/TestViewSupport.java --- @@ -311,6 +311,75 @@ public void createViewWhenViewAlreadyExists() throws Exception { } } + @Test // DRILL-5952 + public void createViewIfNotExistsWhenTableAlreadyExists() throws Exception { + final String tableName = generateViewName(); + + try { + final String tableDef = "SELECT region_id, sales_city FROM cp.`region.json` ORDER BY `region_id` LIMIT 2"; + + test("CREATE TABLE %s.%s as %s", DFS_TMP_SCHEMA, tableName, tableDef); + + // Try to create the view with same name in same schema with if not exists clause. + final String createViewSql = String.format("CREATE VIEW IF NOT EXISTS %s.`%s` AS %s", DFS_TMP_SCHEMA, tableName, tableDef); + + testBuilder() + .sqlQuery(createViewSql) + .unOrdered() + .baselineColumns("ok", "summary") + .baselineValues(false, + String.format("A non-view table with given name [%s] already exists in schema [%s]", tableName, DFS_TMP_SCHEMA)) + .go(); + + } finally { + FileUtils.deleteQuietly(new File(dirTestWatcher.getDfsTestTmpDir(), tableName)); + } + } + + @Test // DRILL-5952 + public void createViewIfNotExistsWhenViewAlreadyExists() throws Exception { + final String viewName = generateViewName(); + + try { + final String viewDef1 = "SELECT region_id, sales_city FROM cp.`region.json` ORDER BY `region_id` LIMIT 2"; + + // Create the view + createViewHelper(DFS_TMP_SCHEMA, viewName, DFS_TMP_SCHEMA, null, viewDef1); + + // Try to create the view with same name in same schema with if not exists clause. + final String viewDef2 = "SELECT sales_state_province FROM cp.`region.json` ORDER BY `region_id`"; + final String createViewSql = String.format("CREATE VIEW IF NOT EXISTS %s.`%s` AS %s", DFS_TMP_SCHEMA, viewName, viewDef2); + + testBuilder() + .sqlQuery(createViewSql) + .unOrdered() + .baselineColumns("ok", "summary") + .baselineValues(false, + String.format("A view with given name [%s] already exists in schema [%s]", viewName, DFS_TMP_SCHEMA)) + .go(); + + // Make sure the view created returns the data expected. + queryViewHelper(String.format("SELECT * FROM %s.`%s` LIMIT 1", DFS_TMP_SCHEMA, viewName), + new String[]{"region_id", "sales_city"}, + ImmutableList.of(new Object[]{0L, "None"}) + ); + } finally { + dropViewHelper(DFS_TMP_SCHEMA, viewName, DFS_TMP_SCHEMA); + } + } + + @Test // DRILL-5952 + public void createViewWithBothOrReplaceAndIfNotExists() throws Exception { + final String viewName = generateViewName(); + + final String viewDef = "SELECT region_id, sales_city FROM cp.`region.json`"; + + // Try to create the view with both and clause. + final String createViewSql = String.format("CREATE OR REPLACE VIEW IF NOT EXISTS %s.`%s` AS %s", DFS_TMP_SCHEMA, viewName, viewDef); + + errorMsgTestHelper(createViewSql, "Create view statement cannot have both and clause"); + } + --- End diff -- Done ---