akashrn5 commented on a change in pull request #3938:
URL: https://github.com/apache/carbondata/pull/3938#discussion_r491814518
##########
File path:
integration/spark/src/main/scala/org/apache/spark/sql/execution/strategy/DDLHelper.scala
##########
@@ -398,9 +398,7 @@ object DDLHelper {
}
def showTables(showTablesCommand: ShowTablesCommand): Seq[SparkPlan] = {
Review comment:
is this method really required? can't we just directly call the command
class from `DDLStrategy `class? Why to add an intermediate method?
##########
File path:
integration/spark/src/main/scala/org/apache/spark/sql/execution/command/table/CarbonShowTablesCommand.scala
##########
@@ -18,35 +18,23 @@
package org.apache.spark.sql.execution.command.table
import org.apache.spark.sql.{Row, SparkSession}
-import org.apache.spark.sql.catalyst.TableIdentifier
-import org.apache.spark.sql.catalyst.expressions.{Attribute,
AttributeReference}
-import org.apache.spark.sql.execution.command.MetadataCommand
-import org.apache.spark.sql.types.{BooleanType, StringType}
+import org.apache.spark.sql.catalyst.expressions.Attribute
+import org.apache.spark.sql.execution.command.{MetadataCommand,
ShowTablesCommand}
-private[sql] case class CarbonShowTablesCommand ( databaseName: Option[String],
- tableIdentifierPattern: Option[String]) extends MetadataCommand{
+private[sql] case class CarbonShowTablesCommand(showTablesCommand:
ShowTablesCommand)
+ extends MetadataCommand {
- // The result of SHOW TABLES has three columns: database, tableName and
isTemporary.
- override val output: Seq[Attribute] = {
- AttributeReference("database", StringType, nullable = false)() ::
- AttributeReference("tableName", StringType, nullable = false)() ::
- AttributeReference("isTemporary", BooleanType, nullable = false)() :: Nil
- }
+ override val output: Seq[Attribute] = showTablesCommand.output
override def processMetadata(sparkSession: SparkSession): Seq[Row] = {
- // Since we need to return a Seq of rows, we will call getTables directly
- // instead of calling tables in sparkSession.
- val catalog = sparkSession.sessionState.catalog
- val db = databaseName.getOrElse(catalog.getCurrentDatabase)
- val tables =
- tableIdentifierPattern.map(catalog.listTables(db,
_)).getOrElse(catalog.listTables(db))
+ val rows = showTablesCommand.run(sparkSession)
val externalCatalog = sparkSession.sharedState.externalCatalog
// this method checks whether the table is mainTable or MV based on
property "isVisible"
- def isMainTable(tableIdent: TableIdentifier) = {
+ def isMainTable(db: String, table: String) = {
Review comment:
move this method after line 46 and also add a comment inside
implementation saying what we filter here.
##########
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
Review comment:
combine rows 41 and 42 and direct do `.collect()` on sql
##########
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:
can you add one query for non carbon table also?
##########
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
Review comment:
no need to create the dataframes, just can use `checkanswer` APIs to
provide `SQL `and `Seg[Rows[]]`, please modify all places
----------------------------------------------------------------
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]