VenuReddy2103 commented on a change in pull request #3938: URL: https://github.com/apache/carbondata/pull/3938#discussion_r492609629
########## File path: integration/spark/src/test/scala/org/apache/carbondata/spark/testsuite/ShowTable/TestShowTable.scala ########## @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.carbondata.spark.testsuite.ShowTable + +import org.apache.spark.sql.Row +import org.apache.spark.sql.test.util.QueryTest +import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach} + +import org.apache.carbondata.common.exceptions.sql.MalformedIndexCommandException + +/** + * Test class for show tables. + */ +class TestShowTable extends QueryTest with BeforeAndAfterAll with BeforeAndAfterEach { + val dbName = "testshowtable" + override def beforeAll: Unit = { + sql(s"drop database if exists $dbName cascade") + sql(s"create database $dbName") + sql(s"use $dbName") + } + + test("test show tables") { + sql("create table employee(id string, name string) stored as carbondata") + sql("create table employee_part(name string) partitioned by (grade int)") + sql("create index employee_si on table employee(name) as 'carbondata'") + sql("create materialized view employee_mv as select name from employee group by name") + val df = sql("show tables").toDF + val rows = df.collect() + val schema = rows(0).schema + assert(schema.length == 3) + assert(schema(0).name.equals("database")) + assert(schema(1).name.equals("tableName")) + assert(schema(2).name.equals("isTemporary")) + // show tables query can return views as well. Just validate if expected rows are present + // and unexpected rows are not present. + val expectedRows = Seq(Row(dbName, "employee", false), + Row(dbName, "employee_part", false), + Row(dbName, "employee_si", false)) + val expectedRowsDF = sqlContext.sparkSession + .createDataFrame(sqlContext.sparkContext.makeRDD[Row](expectedRows), schema) + checkAnswer(df.intersect(expectedRowsDF), expectedRows) + // check if mv table is not present + val notExpectedRows = Seq(Row(dbName, "employee_mv", false)) + val notExpectedRowsDF = sqlContext.sparkSession + .createDataFrame(sqlContext.sparkContext.makeRDD[Row](notExpectedRows), schema) + assert(df.intersect(notExpectedRowsDF).count() == 0) + } + + test("test show table extended like") { + sql("create table employee(id string, name string) stored as carbondata") Review comment: employee_part table is non carbon table ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
