Skip to content

Commit

Permalink
add PPL describe command
Browse files Browse the repository at this point in the history
Signed-off-by: YANGDB <[email protected]>
  • Loading branch information
YANG-DB committed Aug 7, 2024
1 parent 21c92a0 commit 74f261a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package org.opensearch.flint.spark.ppl

import org.apache.spark.sql.{QueryTest, Row}
import org.apache.spark.sql.catalyst.TableIdentifier
import org.apache.spark.sql.catalyst.analysis.{UnresolvedAttribute, UnresolvedRelation, UnresolvedStar}
import org.apache.spark.sql.catalyst.analysis.{UnresolvedAttribute, UnresolvedRelation, UnresolvedStar, UnresolvedTableOrView}
import org.apache.spark.sql.catalyst.expressions.{Ascending, Literal, SortOrder}
import org.apache.spark.sql.catalyst.plans.logical._
import org.apache.spark.sql.execution.command.DescribeTableCommand
Expand Down Expand Up @@ -47,16 +47,29 @@ class FlintSparkPPLBasicITSuite

// Retrieve the results
val results: Array[Row] = frame.collect()
assert(results.length == 2)
// Define the expected results
val expectedResults: Array[Row] = Array(
Row("name", "string", null),
Row("age", "int", null),
Row("state", "string", null),
Row("country", "string", null),
Row("year", "int", null),
Row("month", "int", null),
Row("# Partition Information", "", ""),
Row("# col_name", "data_type", "comment"),
Row("year", "int", null),
Row("month", "int", null)
)
// Compare the results
implicit val rowOrdering: Ordering[Row] = Ordering.by[Row, String](_.getAs[String](0))
assert(results.sorted.sameElements(expectedResults.sorted))
// Retrieve the logical plan
val logicalPlan: LogicalPlan = frame.queryExecution.logical
val logicalPlan: LogicalPlan = frame.queryExecution.commandExecuted.asInstanceOf[CommandResult].commandLogicalPlan
// Define the expected logical plan
val expectedPlan: LogicalPlan =
Project(
Seq(UnresolvedStar(None)),
DescribeTableCommand(TableIdentifier("table"), null, isExtended = false, Seq.empty))
DescribeTableCommand(TableIdentifier("default.flint_ppl_test"), null, isExtended = false, output = Seq())
// Compare the two plans
assert(expectedPlan === logicalPlan)
comparePlans(logicalPlan, expectedPlan, checkAnalysis = false)
}
}

Expand Down Expand Up @@ -232,7 +245,7 @@ class FlintSparkPPLBasicITSuite
val sortedPlan: LogicalPlan =
Sort(Seq(SortOrder(UnresolvedAttribute("age"), Ascending)), global = true, limitPlan)

val expectedPlan = Project(Seq(UnresolvedStar(None)), sortedPlan);
val expectedPlan = Project(Seq(UnresolvedStar(None)), sortedPlan)
// Compare the two plans
assert(compareByString(expectedPlan) === compareByString(logicalPlan))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,19 @@ class PPLLogicalPlanBasicQueriesTranslatorTestSuite
test("test simple describe clause") {
// if successful build ppl logical plan and translate to catalyst logical plan
val context = new CatalystPlanContext
val logPlan = planTransformer.visit(plan(pplParser, "describe table", false), context)
val logPlan = planTransformer.visit(plan(pplParser, "describe t", false), context)

val projectList: Seq[NamedExpression] = Seq(UnresolvedStar(None))
val expectedPlan = Project(projectList, DescribeTableCommand(TableIdentifier("table"), null, isExtended = false, Seq.empty))
val expectedPlan = DescribeTableCommand(TableIdentifier("table"), null, isExtended = false, Seq.empty)
comparePlans(expectedPlan, logPlan, false)
}


test("test FQN table describe clause") {
// if successful build ppl logical plan and translate to catalyst logical plan
val context = new CatalystPlanContext
val logPlan = planTransformer.visit(plan(pplParser, "describe catalog.schema.table", false), context)
val logPlan = planTransformer.visit(plan(pplParser, "describe catalog.schema.t", false), context)

val projectList: Seq[NamedExpression] = Seq(UnresolvedStar(None))
val expectedPlan = Project(projectList, DescribeTableCommand(TableIdentifier("catalog.schema.table"), null, isExtended = false, Seq.empty))
val expectedPlan = DescribeTableCommand(TableIdentifier("catalog.schema.table"), null, isExtended = false, Seq.empty)
comparePlans(expectedPlan, logPlan, false)
}

Expand Down

0 comments on commit 74f261a

Please sign in to comment.