Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

feat(sql-editor): explain on Databricks, and draw Snowflake and Hive plans (#21677)

Danny Xu2a79a3490ac4
diff --git a/backend/api/v1/sql_service_test.go b/backend/api/v1/sql_service_test.go
index 730cb8224a..50d74188e7 100644
--- a/backend/api/v1/sql_service_test.go
+++ b/backend/api/v1/sql_service_test.go
@@ -377,7 +377,7 @@ func TestValidateExplainFormat(t *testing.T) {
{name: "starrocks json is a syntax error on the engine", engine: storepb.Engine_STARROCKS, format: v1pb.QueryOption_JSON, wantErr: true},
{name: "doris text", engine: storepb.Engine_DORIS, format: v1pb.QueryOption_TEXT},
{name: "doris json is a syntax error on the engine too", engine: storepb.Engine_DORIS, format: v1pb.QueryOption_JSON, wantErr: true},
- {name: "hive json is not implemented yet", engine: storepb.Engine_HIVE, format: v1pb.QueryOption_JSON, wantErr: true},
+ {name: "hive json", engine: storepb.Engine_HIVE, format: v1pb.QueryOption_JSON},
{name: "redis explains nothing at all", engine: storepb.Engine_REDIS, format: v1pb.QueryOption_TEXT, wantErr: true},
{name: "mongodb json", engine: storepb.Engine_MONGODB, format: v1pb.QueryOption_JSON},
{name: "mongodb has no text plan", engine: storepb.Engine_MONGODB, format: v1pb.QueryOption_TEXT, wantErr: true},
@@ -386,7 +386,10 @@ func TestValidateExplainFormat(t *testing.T) {
// format must be refused here too rather than reaching the driver.
{name: "cassandra refuses even an unspecified format", engine: storepb.Engine_CASSANDRA, format: v1pb.QueryOption_EXPLAIN_FORMAT_UNSPECIFIED, wantErr: true},
{name: "cosmosdb refuses even an unspecified format", engine: storepb.Engine_COSMOSDB, format: v1pb.QueryOption_EXPLAIN_FORMAT_UNSPECIFIED, wantErr: true},
- {name: "databricks refuses even an unspecified format", engine: storepb.Engine_DATABRICKS, format: v1pb.QueryOption_EXPLAIN_FORMAT_UNSPECIFIED, wantErr: true},
+ // Databricks plans a statement through Spark's own EXPLAIN, whose only
+ // plan is text.
+ {name: "databricks text", engine: storepb.Engine_DATABRICKS, format: v1pb.QueryOption_TEXT},
+ {name: "databricks json has no reader", engine: storepb.Engine_DATABRICKS, format: v1pb.QueryOption_JSON, wantErr: true},
{name: "elasticsearch refuses even an unspecified format", engine: storepb.Engine_ELASTICSEARCH, format: v1pb.QueryOption_EXPLAIN_FORMAT_UNSPECIFIED, wantErr: true},
} {
t.Run(tc.name, func(t *testing.T) {
@@ -408,6 +411,14 @@ func TestValidateExplainFormat(t *testing.T) {
// The engine parsers are registered for the whole v1 test binary by blank imports
// elsewhere in the package, so each call below returns that engine's real verdict
// rather than a no-parser default.
+//
+// Databricks prefixes EXPLAIN too and is left out: it is the one SQL engine with
+// no read-only validator registered, so the gate has nothing to classify the
+// planned form with — for an ordinary query as much as for an explain. What
+// keeps a write from running there is Spark's EXPLAIN, which compiles a
+// statement without executing it, and the planner reading the caller's comments
+// as Databricks does, so a write behind one is planned rather than preserved.
+// See TestExplainGateOnlyPlansOnDatabricks.
var explainPrefixEngines = []storepb.Engine{
storepb.Engine_POSTGRES, storepb.Engine_MYSQL, storepb.Engine_MARIADB,
storepb.Engine_OCEANBASE, storepb.Engine_TIDB, storepb.Engine_REDSHIFT,
@@ -416,6 +427,34 @@ var explainPrefixEngines = []storepb.Engine{
storepb.Engine_TRINO,
}
+// TestExplainGateOnlyPlansOnDatabricks locks what stands in for the smuggle
+// defense on the one engine whose planned form the gate cannot classify: every
+// statement an explain request reaches the driver with begins with EXPLAIN, so
+// Spark compiles it rather than running it. A write the caller sends is planned,
+// not executed.
+func TestExplainGateOnlyPlansOnDatabricks(t *testing.T) {
+ t.Parallel()
+ for _, tc := range []struct {
+ name string
+ statement string
+ want string
+ }{
+ {name: "a write is planned", statement: "DELETE FROM t WHERE id = 1", want: "EXPLAIN FORMATTED DELETE FROM t WHERE id = 1"},
+ {name: "ANALYZE DELETE is planned", statement: "ANALYZE DELETE FROM t", want: "EXPLAIN FORMATTED ANALYZE DELETE FROM t"},
+ // Databricks block comments nest, so the EXPLAIN here is inside one and
+ // the statement is the delete.
+ {name: "a write behind a nested comment", statement: "/* outer /* inner */\nEXPLAIN\n*/\nDELETE FROM t", want: "EXPLAIN FORMATTED /* outer /* inner */\nEXPLAIN\n*/\nDELETE FROM t"},
+ {name: "a plan the caller asked for", statement: "EXPLAIN SELECT 1", want: "EXPLAIN SELECT 1"},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ t.Parallel()
+ planned, err := parserbase.ExplainStatement(storepb.Engine_DATABRICKS, tc.statement, parserbase.ExplainFormatDefault)
+ require.NoError(t, err)
+ require.Equal(t, tc.want, planned)
+ })
+ }
+}
+
// TestExplainGateRejectsSmuggledWrite locks the smuggle defense. An explain
// request carries the bare statement, so "ANALYZE DELETE FROM t" — not valid SQL
// on its own — would become EXPLAIN ANALYZE DELETE and execute the DELETE if
diff --git a/backend/plugin/db/databricks/databricks.go b/backend/plugin/db/databricks/databricks.go
index 9a0884f334..316736462e 100644
--- a/backend/plugin/db/databricks/databricks.go
+++ b/backend/plugin/db/databricks/databricks.go
@@ -84,11 +84,22 @@ func (d *Driver) QueryConn(ctx context.Context, _ *sql.Conn, statement string, q
if err != nil {
return nil, err
}
+ // A blank or comment-only tail is not a statement to run, and on an explain
+ // request it would be planned as one.
+ stmts = base.FilterEmptyStatements(stmts)
for _, stmt := range stmts {
+ text := stmt.Text
+ if queryContext.Explain {
+ explained, err := base.ExplainStatement(storepb.Engine_DATABRICKS, text, db.ExplainFormat(queryContext.Option.GetExplainFormat()))
+ if err != nil {
+ return nil, err
+ }
+ text = explained
+ }
result := &v1pb.QueryResult{}
startTime := time.Now()
- dataArr, colInfo, err := d.execStatementSync(ctx, stmt.Text, int64(queryContext.Limit))
+ dataArr, colInfo, err := d.execStatementSync(ctx, text, int64(queryContext.Limit))
if err != nil {
return nil, err
}
@@ -114,7 +125,7 @@ func (d *Driver) QueryConn(ctx context.Context, _ *sql.Conn, statement string, q
result.Rows = append(result.Rows, queryRow)
}
result.Latency = durationpb.New(time.Since(startTime))
- result.Statement = stmt.Text
+ result.Statement = text
result.RowsCount = int64(len(result.Rows))
results = append(results, result)
}
diff --git a/backend/plugin/db/explain_format.go b/backend/plugin/db/explain_format.go
index 1d2b92fc37..06ea2e5d5a 100644
--- a/backend/plugin/db/explain_format.go
+++ b/backend/plugin/db/explain_format.go
@@ -38,10 +38,14 @@ func SupportedExplainFormats(engine storepb.Engine) []v1pb.QueryOption_ExplainFo
return []v1pb.QueryOption_ExplainFormat{v1pb.QueryOption_JSON}
case storepb.Engine_MYSQL, storepb.Engine_MARIADB, storepb.Engine_TIDB,
storepb.Engine_ORACLE, storepb.Engine_CLICKHOUSE, storepb.Engine_TRINO,
- storepb.Engine_OCEANBASE, storepb.Engine_COCKROACHDB:
+ storepb.Engine_OCEANBASE, storepb.Engine_COCKROACHDB, storepb.Engine_SNOWFLAKE,
+ storepb.Engine_HIVE:
return []v1pb.QueryOption_ExplainFormat{v1pb.QueryOption_TEXT, v1pb.QueryOption_JSON}
+ // These engines have no plan to ask for: CQL and the document and key-value
+ // APIs state none, and an engine listed here is refused an explain request
+ // outright, since its driver would otherwise run the statement as written.
case storepb.Engine_REDIS, storepb.Engine_DYNAMODB,
- storepb.Engine_CASSANDRA, storepb.Engine_COSMOSDB, storepb.Engine_DATABRICKS,
+ storepb.Engine_CASSANDRA, storepb.Engine_COSMOSDB,
storepb.Engine_ELASTICSEARCH:
return nil
default:
diff --git a/backend/plugin/db/explain_format_test.go b/backend/plugin/db/explain_format_test.go
index 3cba1dda76..da31bfde24 100644
--- a/backend/plugin/db/explain_format_test.go
+++ b/backend/plugin/db/explain_format_test.go
@@ -55,6 +55,10 @@ func TestExplainResultFormat(t *testing.T) {
{name: "mongodb json", engine: storepb.Engine_MONGODB, format: v1pb.QueryOption_JSON, want: v1pb.QueryOption_JSON, isPlan: true},
{name: "cockroachdb json", engine: storepb.Engine_COCKROACHDB, format: v1pb.QueryOption_JSON, want: v1pb.QueryOption_JSON, isPlan: true},
{name: "cockroachdb default", engine: storepb.Engine_COCKROACHDB, want: v1pb.QueryOption_TEXT, isPlan: true},
+ {name: "databricks default", engine: storepb.Engine_DATABRICKS, want: v1pb.QueryOption_TEXT, isPlan: true},
+ {name: "snowflake json", engine: storepb.Engine_SNOWFLAKE, format: v1pb.QueryOption_JSON, want: v1pb.QueryOption_JSON, isPlan: true},
+ {name: "snowflake default", engine: storepb.Engine_SNOWFLAKE, want: v1pb.QueryOption_TEXT, isPlan: true},
+ {name: "hive json", engine: storepb.Engine_HIVE, format: v1pb.QueryOption_JSON, want: v1pb.QueryOption_JSON, isPlan: true},
{name: "bigquery dry run", engine: storepb.Engine_BIGQUERY},
} {
t.Run(tc.name, func(t *testing.T) {
@@ -65,6 +69,28 @@ func TestExplainResultFormat(t *testing.T) {
}
}
+// TestSupportedExplainFormats pins which engines are refused an explain request
+// outright. An explain request skips the read-only validation an ordinary query
+// gets, on the understanding that the driver turns the statement into a plan, so
+// an engine whose driver would run the statement as written has to report no
+// format at all.
+func TestSupportedExplainFormats(t *testing.T) {
+ for _, engine := range []storepb.Engine{
+ storepb.Engine_REDIS,
+ storepb.Engine_DYNAMODB,
+ storepb.Engine_CASSANDRA,
+ storepb.Engine_COSMOSDB,
+ storepb.Engine_ELASTICSEARCH,
+ } {
+ require.Emptyf(t, SupportedExplainFormats(engine), "%v", engine)
+ }
+ // Databricks plans a statement through its own SQL, so it takes the text
+ // plan every engine without a reader of its own reports.
+ require.Equal(t,
+ []v1pb.QueryOption_ExplainFormat{v1pb.QueryOption_TEXT},
+ SupportedExplainFormats(storepb.Engine_DATABRICKS))
+}
+
// TestTypedExplainPlan pins how an engine parser's answer about the caller's own
// EXPLAIN reaches the result. A format the parser cannot name is the answer for
// MySQL's omitted FORMAT, and it has to stay unspecified rather than becoming
diff --git a/backend/plugin/db/snowflake/snowflake.go b/backend/plugin/db/snowflake/snowflake.go
index 0965ba71d8..99c0b0b7ed 100644
--- a/backend/plugin/db/snowflake/snowflake.go
+++ b/backend/plugin/db/snowflake/snowflake.go
@@ -24,9 +24,7 @@ import (
"github.com/bytebase/bytebase/backend/plugin/db/transaction"
"github.com/bytebase/bytebase/backend/plugin/db/util"
"github.com/bytebase/bytebase/backend/plugin/parser/base"
-
- // Register how this engine plans a statement, for base.ExplainStatement below.
- _ "github.com/bytebase/bytebase/backend/plugin/parser/snowflake"
+ snowflakeparser "github.com/bytebase/bytebase/backend/plugin/parser/snowflake"
snow "github.com/snowflakedb/gosnowflake/v2"
)
@@ -388,6 +386,9 @@ func (*Driver) QueryConn(ctx context.Context, conn *sql.Conn, statement string,
if err := rows.Err(); err != nil {
return nil, err
}
+ if !queryContext.Explain {
+ r.QueryPlan = db.TypedExplainPlan(snowflakeparser.DescribeExplain(statement))
+ }
return r, nil
}
diff --git a/backend/plugin/parser/snowflake/explain.go b/backend/plugin/parser/snowflake/explain.go
index e290cfb01b..42389bb3c1 100644
--- a/backend/plugin/parser/snowflake/explain.go
+++ b/backend/plugin/parser/snowflake/explain.go
@@ -13,11 +13,10 @@ func init() {
base.RegisterExplainStatementFunc(storepb.Engine_SNOWFLAKE, explainStatement)
}
-// explainStatement implements base.ExplainStatement. Snowflake returns one plan
-// format here whatever the caller asked for: its EXPLAIN USING JSON is a plan of
-// its own shape that nothing downstream reads (the driver capability table offers
-// this engine the default plan only).
-func explainStatement(statement string, _ base.ExplainFormat) (string, error) {
+// explainStatement implements base.ExplainStatement. Snowflake spells its
+// structured plan EXPLAIN USING JSON; any other format the caller names gets
+// the tabular plan, which is the table Snowflake has always returned here.
+func explainStatement(statement string, format base.ExplainFormat) (string, error) {
node, err := singleStatement(statement)
if err != nil {
return "", err
@@ -32,9 +31,31 @@ func explainStatement(statement string, _ base.ExplainFormat) (string, error) {
return statement, nil
}
}
+ if format == base.ExplainFormatJSON {
+ return "EXPLAIN USING JSON " + planned, nil
+ }
return "EXPLAIN " + planned, nil
}
+// DescribeExplain returns the output format of an EXPLAIN statement and whether
+// it executes the statement it plans. Snowflake's EXPLAIN compiles a statement
+// without running it, whichever format it names, so nothing here executes.
+func DescribeExplain(statement string) (format string, executed bool, ok bool) {
+ node, err := singleStatement(statement)
+ if err != nil {
+ return "", false, false
+ }
+ explain, ok := node.(*ast.ExplainStmt)
+ if !ok {
+ return "", false, false
+ }
+ if explain.Format == ast.ExplainJSON {
+ return "json", false, true
+ }
+ // The tabular and text formats are both tables of operations.
+ return "text", false, true
+}
+
// singleStatement returns the one statement in text. An explain request plans one
// statement at a time: both the drivers and the API gate split a multi-statement
// request first.
diff --git a/backend/plugin/parser/snowflake/explain_test.go b/backend/plugin/parser/snowflake/explain_test.go
index 7f630d032a..4a4cfaa78f 100644
--- a/backend/plugin/parser/snowflake/explain_test.go
+++ b/backend/plugin/parser/snowflake/explain_test.go
@@ -28,6 +28,55 @@ func TestExplainStatement(t *testing.T) {
}
}
+// TestExplainStatementJSON pins the statement that asks Snowflake for the
+// structured plan the viewer draws, and that a caller's own EXPLAIN is
+// replanned in the format asked for rather than wrapped in a second one.
+func TestExplainStatementJSON(t *testing.T) {
+ tests := []struct {
+ statement string
+ want string
+ }{
+ {"SELECT 1", "EXPLAIN USING JSON SELECT 1"},
+ {"EXPLAIN SELECT 1", "EXPLAIN USING JSON SELECT 1"},
+ {"EXPLAIN USING TABULAR SELECT 1", "EXPLAIN USING JSON SELECT 1"},
+ {"EXPLAIN USING JSON SELECT 1", "EXPLAIN USING JSON SELECT 1"},
+ }
+ for _, tc := range tests {
+ got, err := explainStatement(tc.statement, base.ExplainFormatJSON)
+ require.NoErrorf(t, err, "%q", tc.statement)
+ require.Equalf(t, tc.want, got, "%q", tc.statement)
+ }
+ // Only JSON has a reader; every other format gets the tabular plan.
+ for _, format := range []base.ExplainFormat{base.ExplainFormatText, base.ExplainFormatXML, base.ExplainFormatYAML} {
+ got, err := explainStatement("SELECT 1", format)
+ require.NoError(t, err)
+ require.Equal(t, "EXPLAIN SELECT 1", got)
+ }
+}
+
+// TestDescribeExplain pins what a result says about a plan the caller asked for
+// in their own statement. Snowflake's EXPLAIN compiles without running, so no
+// format of it executes what it plans.
+func TestDescribeExplain(t *testing.T) {
+ for _, tc := range []struct {
+ statement string
+ format string
+ isExplain bool
+ }{
+ {statement: "SELECT 1"},
+ {statement: "EXPLAIN SELECT 1", format: "text", isExplain: true},
+ {statement: "EXPLAIN USING TABULAR SELECT 1", format: "text", isExplain: true},
+ {statement: "EXPLAIN USING TEXT SELECT 1", format: "text", isExplain: true},
+ {statement: "EXPLAIN USING JSON SELECT 1", format: "json", isExplain: true},
+ {statement: "explain using json select 1", format: "json", isExplain: true},
+ } {
+ format, executed, isExplain := DescribeExplain(tc.statement)
+ require.Equalf(t, tc.format, format, "%q", tc.statement)
+ require.Falsef(t, executed, "%q", tc.statement)
+ require.Equalf(t, tc.isExplain, isExplain, "%q", tc.statement)
+ }
+}
+
func TestExplainStatementRejects(t *testing.T) {
for _, statement := range []string{
"SELECT 1; SELECT 2",
diff --git a/backend/plugin/parser/standard/explain.go b/backend/plugin/parser/standard/explain.go
index e279cbcdf6..0835615c3a 100644
--- a/backend/plugin/parser/standard/explain.go
+++ b/backend/plugin/parser/standard/explain.go
@@ -1,28 +1,97 @@
package standard
import (
+ "strings"
+
storepb "github.com/bytebase/bytebase/backend/generated-go/store"
"github.com/bytebase/bytebase/backend/plugin/parser/base"
)
func init() {
base.RegisterExplainStatementFunc(storepb.Engine_CLICKHOUSE, clickhouseExplainStatement)
- base.RegisterExplainStatementFunc(storepb.Engine_HIVE, explainStatement)
+ base.RegisterExplainStatementFunc(storepb.Engine_DATABRICKS, databricksExplainStatement)
+ base.RegisterExplainStatementFunc(storepb.Engine_HIVE, hiveExplainStatement)
}
-// explainStatement implements base.ExplainStatement for the engines parsed only
-// as text here. With no AST to ask which statement an EXPLAIN plans, a statement
-// that already asks for a plan runs as the user wrote it; that keeps a request
-// from planning a plan, which is what the rest of this package can promise.
-// Hive returns one plan format whatever the caller asked for; the driver
-// capability table offers it the default plan only.
-func explainStatement(statement string, _ base.ExplainFormat) (string, error) {
+// hiveExplainStatement asks Hive for the structured plan the query-plan viewer
+// draws. FORMATTED answers with one JSON object, whose CBOPlan is the plan
+// Calcite built; every other format of Hive's EXPLAIN is a tree of lines.
+//
+// With no AST to ask which statement an EXPLAIN plans, a statement that already
+// asks for a plan runs as the user wrote it; that keeps a request from planning
+// a plan, which is what the rest of this package can promise.
+func hiveExplainStatement(statement string, format base.ExplainFormat) (string, error) {
if base.StartsWithExplain(statement) {
return statement, nil
}
+ if format == base.ExplainFormatJSON {
+ return "EXPLAIN FORMATTED " + statement, nil
+ }
return "EXPLAIN " + statement, nil
}
+// databricksExplainStatement asks for Spark's FORMATTED plan, which is a tree
+// of numbered operators followed by a block of detail for each, where a plain
+// EXPLAIN prints one tree with every operator's arguments inline. Databricks
+// SQL is Spark SQL, and FORMATTED has been there since Spark 3.0.
+//
+// Databricks prints this one plan whatever the caller asks for. A statement
+// that already asks for a plan runs as the user wrote it, keeping the mode it
+// named; EXPLAIN never executes what it plans, so the planned form of a write
+// is a plan of that write.
+//
+// Which statement that is has to be read the way Databricks reads it. Its block
+// comments nest, so `/* a /* b */ EXPLAIN */ DELETE FROM t` is a DELETE with the
+// EXPLAIN inside the comment, and preserving it as the caller's own plan would
+// run the delete. The engines sharing this file stop at the first `*/` because a
+// read-only validator is registered for them, which refuses such a statement at
+// the gate; Databricks has none.
+func databricksExplainStatement(statement string, _ base.ExplainFormat) (string, error) {
+ if base.StartsWithExplain(pastNestedComments(statement)) {
+ return statement, nil
+ }
+ return "EXPLAIN FORMATTED " + statement, nil
+}
+
+// pastNestedComments returns statement from its first token that is not a
+// comment, counting the depth of block comments rather than ending one at the
+// first `*/`. A comment left open runs to the end of the statement, which
+// leaves no token at all.
+func pastNestedComments(statement string) string {
+ s := statement
+ for {
+ s = strings.TrimLeft(s, " \t\r\n\v\f")
+ switch {
+ case strings.HasPrefix(s, "--"):
+ _, rest, found := strings.Cut(s, "\n")
+ if !found {
+ return ""
+ }
+ s = rest
+ case strings.HasPrefix(s, "/*"):
+ depth, at := 1, len("/*")
+ for depth > 0 && at < len(s) {
+ switch {
+ case strings.HasPrefix(s[at:], "/*"):
+ depth++
+ at += len("/*")
+ case strings.HasPrefix(s[at:], "*/"):
+ depth--
+ at += len("*/")
+ default:
+ at++
+ }
+ }
+ if depth > 0 {
+ return ""
+ }
+ s = s[at:]
+ default:
+ return s
+ }
+ }
+}
+
// clickhouseExplainStatement asks ClickHouse for the structured plan the
// query-plan viewer draws. `indexes = 1` is what makes each read report how
// many parts and granules its indexes let it skip, which is what a ClickHouse
diff --git a/backend/plugin/parser/standard/explain_test.go b/backend/plugin/parser/standard/explain_test.go
index 6a5a814285..a50329e4af 100644
--- a/backend/plugin/parser/standard/explain_test.go
+++ b/backend/plugin/parser/standard/explain_test.go
@@ -24,7 +24,7 @@ func TestExplainStatement(t *testing.T) {
{"-- plan it\nEXPLAIN SELECT 1", "-- plan it\nEXPLAIN SELECT 1"},
}
for _, tc := range tests {
- got, err := explainStatement(tc.statement, base.ExplainFormatDefault)
+ got, err := hiveExplainStatement(tc.statement, base.ExplainFormatDefault)
require.NoErrorf(t, err, "%q", tc.statement)
require.Equalf(t, tc.want, got, "%q", tc.statement)
}
@@ -55,12 +55,86 @@ func TestClickhouseExplainStatement(t *testing.T) {
}
}
-// TestHiveKeepsItsOneFormat locks Hive to the plan it has always returned: it
-// shares this file with ClickHouse but has no structured plan of its own.
-func TestHiveKeepsItsOneFormat(t *testing.T) {
- for _, format := range []base.ExplainFormat{base.ExplainFormatDefault, base.ExplainFormatJSON} {
- got, err := explainStatement("SELECT 1", format)
+// TestDatabricksExplainStatement pins Spark's FORMATTED plan as the one
+// Databricks is asked for: a numbered tree with a block of detail per
+// operator, rather than the one dense tree a plain EXPLAIN prints.
+func TestDatabricksExplainStatement(t *testing.T) {
+ tests := []struct {
+ statement string
+ want string
+ }{
+ {"SELECT 1", "EXPLAIN FORMATTED SELECT 1"},
+ {"SELECT 1;", "EXPLAIN FORMATTED SELECT 1;"},
+ // A write is planned, not run: EXPLAIN never executes what it plans.
+ {"DELETE FROM t WHERE id = 1", "EXPLAIN FORMATTED DELETE FROM t WHERE id = 1"},
+ // Without an AST the user's own EXPLAIN is left as written, so it keeps
+ // whichever mode it named.
+ {"EXPLAIN EXTENDED SELECT 1", "EXPLAIN EXTENDED SELECT 1"},
+ {"-- plan it\nEXPLAIN COST SELECT 1", "-- plan it\nEXPLAIN COST SELECT 1"},
+ }
+ for _, tc := range tests {
+ got, err := databricksExplainStatement(tc.statement, base.ExplainFormatDefault)
+ require.NoErrorf(t, err, "%q", tc.statement)
+ require.Equalf(t, tc.want, got, "%q", tc.statement)
+ }
+ // Databricks prints this one plan whatever format the caller names.
+ for _, format := range []base.ExplainFormat{base.ExplainFormatJSON, base.ExplainFormatText, base.ExplainFormatXML} {
+ got, err := databricksExplainStatement("SELECT 1", format)
+ require.NoError(t, err)
+ require.Equal(t, "EXPLAIN FORMATTED SELECT 1", got)
+ }
+}
+
+// TestDatabricksExplainReadsNestedComments locks the one thing between an
+// explain request and a write on the engine with no read-only validator.
+// Databricks block comments nest, so a statement whose EXPLAIN sits inside one
+// is not a plan the caller asked for: Spark runs
+// `/* a /* b */ EXPLAIN */ SELECT 1` as the SELECT, which this planned instead.
+func TestDatabricksExplainReadsNestedComments(t *testing.T) {
+ tests := []struct {
+ statement string
+ want string
+ }{
+ // The comment runs past the EXPLAIN, so the statement is the DELETE and
+ // gets planned rather than preserved.
+ {
+ "/* outer /* inner */\nEXPLAIN\n*/\nDELETE FROM t",
+ "EXPLAIN FORMATTED /* outer /* inner */\nEXPLAIN\n*/\nDELETE FROM t",
+ },
+ {"/* a /* b */ EXPLAIN */ SELECT 1", "EXPLAIN FORMATTED /* a /* b */ EXPLAIN */ SELECT 1"},
+ // A nested comment that closes before a real EXPLAIN leaves the plan the
+ // caller asked for.
+ {"/* a /* b */ */ EXPLAIN SELECT 1", "/* a /* b */ */ EXPLAIN SELECT 1"},
+ // A comment left open runs to the end, so there is no statement to
+ // preserve.
+ {"/* a /* b */ EXPLAIN SELECT 1", "EXPLAIN FORMATTED /* a /* b */ EXPLAIN SELECT 1"},
+ // A line comment ends at its newline, nested or not.
+ {"-- /* a\n/* b */ EXPLAIN SELECT 1", "-- /* a\n/* b */ EXPLAIN SELECT 1"},
+ }
+ for _, tc := range tests {
+ got, err := databricksExplainStatement(tc.statement, base.ExplainFormatDefault)
+ require.NoErrorf(t, err, "%q", tc.statement)
+ require.Equalf(t, tc.want, got, "%q", tc.statement)
+ }
+}
+
+// TestHiveExplainStatementJSON pins the statement that asks Hive for the one
+// plan it states as a document: FORMATTED answers with JSON, and every other
+// format with a tree of lines.
+func TestHiveExplainStatementJSON(t *testing.T) {
+ got, err := hiveExplainStatement("SELECT 1", base.ExplainFormatJSON)
+ require.NoError(t, err)
+ require.Equal(t, "EXPLAIN FORMATTED SELECT 1", got)
+
+ for _, format := range []base.ExplainFormat{base.ExplainFormatDefault, base.ExplainFormatText, base.ExplainFormatXML} {
+ got, err := hiveExplainStatement("SELECT 1", format)
require.NoError(t, err)
require.Equal(t, "EXPLAIN SELECT 1", got)
}
+
+ // Without an AST, a statement that already asks for a plan runs as the user
+ // wrote it, so a typed EXPLAIN keeps the format it named.
+ got, err = hiveExplainStatement("EXPLAIN EXTENDED SELECT 1", base.ExplainFormatJSON)
+ require.NoError(t, err)
+ require.Equal(t, "EXPLAIN EXTENDED SELECT 1", got)
}
diff --git a/docs/design/query-plan-visualizer.md b/docs/design/query-plan-visualizer.md
index 1a7f1b606d..1ac21d5315 100644
--- a/docs/design/query-plan-visualizer.md
+++ b/docs/design/query-plan-visualizer.md
@@ -28,7 +28,7 @@ This ordering is a judgment call, not a measurement.
## 2. Background / problem
The editor explained on 12 engines and drew a picture for 3 (PostgreSQL, SQL
-Server, Spanner); it now explains on 17 and draws for 15 (§3.4). Reaching the
+Server, Spanner); it now explains on 18 and draws for 17 (§3.4). Reaching the
picture takes five steps: Ctrl/Cmd+E → plan rows in the grid → click a small
"Visualize Explain" link → Bytebase runs `EXPLAIN` a second time for JSON → a
separate browser tab opens.
@@ -353,6 +353,9 @@ regression.
| **Redshift** | one `Query()`, on demand, cached | graph, drawn from the text plan | none — `EXPLAIN` never analyzes |
| **StarRocks** | one `Query()`, on demand, cached | graph, drawn from the text plan | none — `EXPLAIN ANALYZE` executes |
| **Doris** | one `Query()`, on demand, cached | graph, drawn from the text plan by the StarRocks parser | none — Doris has no `EXPLAIN ANALYZE` |
+| **Snowflake** | one `Query()`, on demand, cached | graph, with pruning in place of estimates | none — `EXPLAIN` compiles without running, whichever format it names |
+| **Hive** | one `Query()`, on demand, cached | graph, with rows and row widths, no costs | none in the editor |
+| **Databricks** | one `Query()`, on demand, cached | text: Spark's `EXPLAIN FORMATTED` has no parser yet | none — `EXPLAIN` never executes what it plans |
| **Hive, Snowflake** | one `Query()`, on demand, cached | text | per engine, text at most |
A plan opened from a result is always an estimate, on every engine. Measured
@@ -396,18 +399,25 @@ statistics, and if the slow run was caused by stale statistics that have since
refreshed, the plan shown is the *good* one, and the reader concludes the query
was never the problem. That is the inverted failure this wording exists to stop.
-**Two of the seventeen engines the editor explains have no parser**, so for
-those the plan is text. Showing a text plan as formatted text instead of grid
-rows is a small change with wide reach.
-
-**Hive's
-`EXPLAIN FORMATTED` does**, and is the next graph to add: it returns the stages
-of a Tez DAG, each holding its vertices' operator trees, so it is a third shape
-again rather than another tree to walk, and pinning it needs a warehouse with
-statistics behind it — a plan whose every operator reports "Column stats: NONE"
-is not a fixture worth keeping. **Snowflake's `EXPLAIN USING JSON` also does**,
-but it runs nowhere but Snowflake, and a parser written against documentation
-rather than output is how a viewer learns to draw a plan no server emits.
+**One of the eighteen engines the editor explains has no parser**, so there the
+plan is text. Databricks is that one, and it is the engine this section had
+listed as explaining nothing at all: its driver runs whatever SQL it is handed,
+so the capability table refused explain requests to keep an unplanned statement
+from running — an explain request skips the read-only validation an ordinary
+query gets. It now asks for Spark's `EXPLAIN FORMATTED`, a numbered tree
+followed by a block of detail per operator, which is the shape the Redshift and
+StarRocks parsers already read, so the graph is a parser away rather than a
+question to answer.
+
+**Hive and Snowflake draw, and neither publishes what this section assumed.**
+Hive's `EXPLAIN FORMATTED` answers with one JSON object whose `CBOPlan` is
+Calcite's own plan: a flat list of operators, each naming the ones it reads,
+beside the Tez stages that were the reason to defer it. The stages are a third
+shape again; the CBO plan is a tree to walk. Hive states it only where its
+cost-based optimizer planned the statement, and where it does not the viewer
+shows the plan as text. Snowflake's `EXPLAIN USING JSON` runs nowhere but
+Snowflake, so its fixture is the output Snowflake publishes rather than a
+capture through the driver, which is recorded beside the fixture.
**What each new engine's plans do and do not carry.** Oracle states a plan as
rows of `PLAN_TABLE` rather than as a document, and no EXPLAIN option of its
@@ -419,6 +429,18 @@ EXPLAIN it offers, so its plans rank nothing and shade by rows, but with
`indexes = 1` each read reports the parts and granules its indexes let it skip,
which is what a ClickHouse plan is read for.
+Snowflake estimates neither cost nor rows. What it states instead is how much
+of each table the query would read — the micro-partitions assigned out of the
+table's total, and the bytes they hold — so its plans rank nothing, and a scan
+assigned every partition of a table with more than one carries the full-scan
+warning. Hive states a row count and an average row width per operator, and a
+cost on its joins alone, which on a table nothing has analyzed reads "not
+available"; so its plans rank nothing either and shade by rows. Both are read
+from documents Calcite and Snowflake write for their own tooling, which is why
+each parser turns an edge list around rather than walking a tree: Snowflake
+names each operation's parents, Hive leaves an operator's one input out and
+means the operator declared before it.
+
Neither MySQL nor MariaDB names
the stored table a `table` entry reads — it prints the alias where the statement
gave one, unqualified, and nothing in the plan says which it is. TiDB and
@@ -777,6 +799,14 @@ Checked against `main` on 2026-10-27, at [#21669](https://github.com/bytebase/by
unknown answer as text
([#21670](https://github.com/bytebase/bytebase/pull/21670)).
+- §3.4 — Databricks explains, and Snowflake and Hive draw. Databricks is asked
+ for Spark's `EXPLAIN FORMATTED` and was refused an explain request before,
+ since its driver runs the statement it is handed; its plan is text for now.
+ Snowflake is asked for `EXPLAIN USING JSON` and Hive for
+ `EXPLAIN FORMATTED`, whose `CBOPlan` is Calcite's own plan. Neither ranks
+ anything: Snowflake estimates no cost and Hive states one on its joins
+ alone ([#21677](https://github.com/bytebase/bytebase/pull/21677)).
+
**Not yet**
Nothing: every section of this design is implemented. The one question §3.3
diff --git a/frontend/src/apps/explain-visualizer/QueryPlanView.test.tsx b/frontend/src/apps/explain-visualizer/QueryPlanView.test.tsx
index 42c363ff6f..db3da2e7bc 100644
--- a/frontend/src/apps/explain-visualizer/QueryPlanView.test.tsx
+++ b/frontend/src/apps/explain-visualizer/QueryPlanView.test.tsx
@@ -41,6 +41,8 @@ describe("QueryPlanView", () => {
[Engine.OCEANBASE]: "oceanbase",
[Engine.MONGODB]: "mongodb",
[Engine.COCKROACHDB]: "cockroachdb",
+ [Engine.SNOWFLAKE]: "snowflake",
+ [Engine.HIVE]: "hive",
[Engine.REDSHIFT]: "redshift",
[Engine.STARROCKS]: "starrocks",
[Engine.DORIS]: "starrocks",
diff --git a/frontend/src/apps/explain-visualizer/QueryPlanView.tsx b/frontend/src/apps/explain-visualizer/QueryPlanView.tsx
index e564bc4609..c73bfa711e 100644
--- a/frontend/src/apps/explain-visualizer/QueryPlanView.tsx
+++ b/frontend/src/apps/explain-visualizer/QueryPlanView.tsx
@@ -12,6 +12,11 @@ import {
COCKROACHDB_PLAN_INVALID_JSON_MESSAGE,
COCKROACHDB_PLAN_NO_PLAN_MESSAGE,
} from "./cockroachdb-plan";
+import {
+ HIVE_PLAN_EMPTY_MESSAGE,
+ HIVE_PLAN_INVALID_JSON_MESSAGE,
+ HIVE_PLAN_NO_PLAN_MESSAGE,
+} from "./hive-plan";
import {
MONGODB_PLAN_EMPTY_MESSAGE,
MONGODB_PLAN_INVALID_JSON_MESSAGE,
@@ -59,6 +64,11 @@ import {
REDSHIFT_PLAN_EMPTY_MESSAGE,
REDSHIFT_PLAN_NO_PLAN_MESSAGE,
} from "./redshift-plan";
+import {
+ SNOWFLAKE_PLAN_EMPTY_MESSAGE,
+ SNOWFLAKE_PLAN_INVALID_JSON_MESSAGE,
+ SNOWFLAKE_PLAN_NO_PLAN_MESSAGE,
+} from "./snowflake-plan";
import {
SPANNER_PLAN_EMPTY_MESSAGE,
SPANNER_PLAN_EMULATOR_MESSAGE,
@@ -117,6 +127,12 @@ const PARSE_ERROR_KEYS = new Map<string, QueryPlanTranslationKey>([
[MONGODB_PLAN_EMPTY_MESSAGE, "error.mongodb-empty"],
[MONGODB_PLAN_INVALID_JSON_MESSAGE, "error.mongodb-invalid"],
[MONGODB_PLAN_NO_PLAN_MESSAGE, "error.mongodb-no-plan"],
+ [SNOWFLAKE_PLAN_EMPTY_MESSAGE, "error.snowflake-empty"],
+ [SNOWFLAKE_PLAN_INVALID_JSON_MESSAGE, "error.snowflake-invalid"],
+ [SNOWFLAKE_PLAN_NO_PLAN_MESSAGE, "error.snowflake-no-plan"],
+ [HIVE_PLAN_EMPTY_MESSAGE, "error.hive-empty"],
+ [HIVE_PLAN_INVALID_JSON_MESSAGE, "error.hive-invalid"],
+ [HIVE_PLAN_NO_PLAN_MESSAGE, "error.hive-no-plan"],
[COCKROACHDB_PLAN_EMPTY_MESSAGE, "error.cockroachdb-empty"],
[COCKROACHDB_PLAN_INVALID_JSON_MESSAGE, "error.cockroachdb-invalid"],
[COCKROACHDB_PLAN_NO_PLAN_MESSAGE, "error.cockroachdb-no-plan"],
diff --git a/frontend/src/apps/explain-visualizer/hive-plan.test.ts b/frontend/src/apps/explain-visualizer/hive-plan.test.ts
new file mode 100644
index 0000000000..da50c09b6e
--- /dev/null
+++ b/frontend/src/apps/explain-visualizer/hive-plan.test.ts
@@ -0,0 +1,212 @@
+import { describe, expect, test } from "vitest";
+import {
+ HIVE_PLAN_EMPTY_MESSAGE,
+ HIVE_PLAN_INVALID_JSON_MESSAGE,
+ HIVE_PLAN_NO_PLAN_MESSAGE,
+ parseHivePlan,
+} from "./hive-plan";
+import {
+ PLAN_TOO_DEEP_MESSAGE,
+ type PlanNode,
+ type PlanTree,
+} from "./plan-model";
+import analyzedJoin from "./test-data/hive/analyzed-join.json";
+import joinAggregate from "./test-data/hive/join-aggregate.json";
+import noCboPlan from "./test-data/hive/no-cbo-plan.json";
+import orderLimit from "./test-data/hive/order-limit.json";
+import singleScan from "./test-data/hive/single-scan.json";
+import unionAll from "./test-data/hive/union-all.json";
+
+/** A plan of `rels`, as Hive nests one: Calcite's JSON within the answer. */
+const planOf = (rels: Record<string, unknown>[]): string =>
+ JSON.stringify({ CBOPlan: JSON.stringify({ rels }) });
+
+/** A chain of `depth` operators, which is what drives the depth limit. */
+const nestedPlan = (depth: number): string => {
+ const rels: Record<string, unknown>[] = [
+ { id: "0", relOp: "HiveTableScan", table: ["default", "t"], inputs: [] },
+ ];
+ for (let level = 1; level < depth; level += 1) {
+ rels.push({ id: String(level), relOp: "HiveFilter" });
+ }
+ return planOf(rels);
+};
+
+const parse = (source: string): PlanTree => {
+ const result = parseHivePlan(source);
+ if (!result.ok)
+ throw new Error(`expected a parsable plan: ${result.message}`);
+ return result.tree;
+};
+
+const parseFixture = (fixture: unknown): PlanTree =>
+ parse(JSON.stringify(fixture));
+
+const outline = (tree: PlanTree): string[] =>
+ tree.nodes.map(
+ (node) => `${node.id} ${node.nodeType} ${node.subject ?? "-"}`
+ );
+
+const propertyValue = (node: PlanNode, label: string): string | undefined =>
+ node.properties.find((property) => property.label === label)?.value;
+
+describe("parseHivePlan", () => {
+ test("reads a chain whose operators name no input", () => {
+ // Calcite leaves `inputs` out when an operator reads the one declared
+ // before it, so the chain is the list read backwards from the last.
+ const tree = parseFixture(singleScan);
+ expect(outline(tree)).toEqual([
+ "0 HiveProject id, name, city",
+ "0.0 HiveFilter =",
+ // The alias the statement gave the table is the table's own name here,
+ // so the card does not repeat it.
+ "0.0.0 HiveTableScan default.customers",
+ ]);
+ });
+
+ test("follows the inputs a join names, and reads its row counts", () => {
+ const tree = parseFixture(joinAggregate);
+ expect(outline(tree)).toEqual([
+ "0 HiveProject city, _o__c1",
+ "0.0 HiveAggregate count",
+ "0.0.0 HiveProject $f0",
+ "0.0.0.0 HiveJoin =",
+ "0.0.0.0.0 HiveProject id",
+ "0.0.0.0.0.0 HiveFilter AND",
+ "0.0.0.0.0.0.0 HiveTableScan default.customers c",
+ "0.0.0.0.1 HiveProject customer_id",
+ "0.0.0.0.1.0 HiveFilter IS NOT NULL",
+ "0.0.0.0.1.0.0 HiveTableScan default.orders o",
+ ]);
+ const scan = tree.nodes[6];
+ expect(scan.rows).toBe(1);
+ expect(scan.width).toBe(104);
+ expect(propertyValue(scan, "Join type")).toBeUndefined();
+ expect(propertyValue(tree.nodes[3], "Join type")).toBe("inner");
+ });
+
+ test("resolves a scan's table from the name Hive qualifies", () => {
+ const tree = parseFixture(joinAggregate);
+ expect(tree.nodes[6].relation).toEqual({
+ database: "default",
+ table: "customers",
+ });
+ expect(tree.root.relation).toBeUndefined();
+ });
+
+ test("draws both sides of a union", () => {
+ const tree = parseFixture(unionAll);
+ expect(
+ tree.nodes.filter((node) => node.nodeType === "HiveTableScan")
+ ).toHaveLength(2);
+ expect(tree.root.children).toHaveLength(2);
+ });
+
+ test("reads a sort and its fetch", () => {
+ const tree = parseFixture(orderLimit);
+ expect(outline(tree).some((line) => line.includes("HiveSortLimit"))).toBe(
+ true
+ );
+ });
+
+ test("reads the row counts of tables Hive has analyzed", () => {
+ // The same query against analyzed tables: the scan states the table's rows
+ // and its average row width, and the filter above it states what the
+ // optimizer expects its predicate to leave.
+ const tree = parseFixture(analyzedJoin);
+ const scan = tree.nodes.find(
+ (node) => node.relation?.table === "customers_d"
+ );
+ expect(scan?.rows).toBe(5);
+ expect(scan?.width).toBe(9.4);
+ expect(tree.nodes[5].nodeType).toBe("HiveFilter");
+ expect(tree.nodes[5].rows).toBeCloseTo(1.667, 3);
+ expect(tree.maxRows).toBe(6);
+ });
+
+ test("ranks nothing, since only a join states a cost", () => {
+ const tree = parseFixture(joinAggregate);
+ expect(tree.estimates.cost).toBe(false);
+ expect(tree.estimates.rows).toBe(true);
+ // Hive states the cost it could not compute as words, which is why none of
+ // them is read as a number. It says the same of an analyzed table, so the
+ // numbers a reader gets are rows and widths.
+ expect(propertyValue(tree.nodes[3], "Cost")).toBe("not available");
+ const analyzed = parseFixture(analyzedJoin);
+ expect(analyzed.estimates.cost).toBe(false);
+ expect(
+ propertyValue(
+ analyzed.nodes.find((node) => node.nodeType === "HiveJoin") ??
+ analyzed.root,
+ "Cost"
+ )
+ ).toBe("not available");
+ });
+
+ test("keeps the column count rather than the column list", () => {
+ const tree = parseFixture(singleScan);
+ expect(propertyValue(tree.nodes[2], "Columns")).toBe("7");
+ // The condition tree is the query's own syntax; the operator it applies is
+ // what reads as a fact.
+ expect(propertyValue(tree.nodes[1], "Condition")).toBe("=");
+ });
+
+ test("says so when the optimizer planned nothing", () => {
+ // Hive states a CBO plan only when its cost-based optimizer ran; the stages
+ // it leaves instead are not an operator tree.
+ expect(parseHivePlan(JSON.stringify(noCboPlan))).toEqual({
+ ok: false,
+ message: HIVE_PLAN_NO_PLAN_MESSAGE,
+ });
+ expect(parseHivePlan(planOf([]))).toEqual({
+ ok: false,
+ message: HIVE_PLAN_NO_PLAN_MESSAGE,
+ });
+ });
+
+ test("says so when there is no plan to read", () => {
+ expect(parseHivePlan("")).toEqual({
+ ok: false,
+ message: HIVE_PLAN_EMPTY_MESSAGE,
+ });
+ expect(parseHivePlan("not json")).toEqual({
+ ok: false,
+ message: HIVE_PLAN_INVALID_JSON_MESSAGE,
+ });
+ expect(parseHivePlan("[]")).toEqual({
+ ok: false,
+ message: HIVE_PLAN_INVALID_JSON_MESSAGE,
+ });
+ expect(parseHivePlan(JSON.stringify({ CBOPlan: "not json" }))).toEqual({
+ ok: false,
+ message: HIVE_PLAN_INVALID_JSON_MESSAGE,
+ });
+ });
+
+ test("stops at an operator that reads itself", () => {
+ const tree = parse(
+ planOf([
+ {
+ id: "0",
+ relOp: "HiveTableScan",
+ table: ["default", "t"],
+ inputs: [],
+ },
+ { id: "1", relOp: "HiveJoin", inputs: ["0", "2"] },
+ { id: "2", relOp: "HiveProject", inputs: ["1"] },
+ ])
+ );
+ expect(outline(tree)).toEqual([
+ "0 HiveProject -",
+ "0.0 HiveJoin -",
+ "0.0.0 HiveTableScan default.t",
+ ]);
+ });
+
+ test("refuses a plan deeper than the viewer draws", () => {
+ expect(parseHivePlan(nestedPlan(600))).toEqual({
+ ok: false,
+ message: PLAN_TOO_DEEP_MESSAGE,
+ });
+ });
+});
diff --git a/frontend/src/apps/explain-visualizer/hive-plan.ts b/frontend/src/apps/explain-visualizer/hive-plan.ts
new file mode 100644
index 0000000000..af6e957796
--- /dev/null
+++ b/frontend/src/apps/explain-visualizer/hive-plan.ts
@@ -0,0 +1,282 @@
+import {
+ addPlanProperty,
+ checkPlanDepth,
+ isJsonRecord,
+ type JsonRecord,
+ type PlanNode,
+ type PlanParseResult,
+ type PlanProperty,
+ type PlanRelation,
+ parseWithDepthLimit,
+ planLabel,
+ planSizeBudget,
+} from "./plan-model";
+
+/**
+ * Maps `EXPLAIN FORMATTED` output onto the engine-neutral plan model.
+ *
+ * Hive answers with one JSON object whose `CBOPlan` is itself a JSON string:
+ * Calcite's own plan, a flat list of operators in the order they were built.
+ * An operator that names no `inputs` reads the one declared before it, which
+ * is how Calcite writes a chain; the ones that name them are the joins and
+ * unions, and the last operator in the list is the root.
+ *
+ * Its row counts and average row sizes are read. Its costs are not: only a
+ * join reports one, and on a table nothing has analyzed it reports the string
+ * "not available", so a ranking would rest on the one number the plan is least
+ * sure of.
+ *
+ * Without CBO there is no `CBOPlan` at all — `STAGE DEPENDENCIES` and
+ * `STAGE PLANS` are left, which describe the Tez or MapReduce stages rather
+ * than an operator tree — and the viewer shows the plan as text instead.
+ */
+
+const PLAN_KEY = "CBOPlan";
+const INPUTS_KEY = "inputs";
+
+/** Keys the model promotes to typed fields, so the property list drops them. */
+const PROMOTED_KEYS = new Set([
+ "id",
+ "relOp",
+ "table",
+ "rowCount",
+ "avgRowSize",
+ INPUTS_KEY,
+]);
+
+/** Calcite names an operator by its class: `…reloperators.HiveTableScan`. */
+const OPERATOR_CLASS = /([^.]+)$/;
+
+export const HIVE_PLAN_EMPTY_MESSAGE =
+ "Hive returned no query plan for this statement.";
+export const HIVE_PLAN_INVALID_JSON_MESSAGE =
+ "The query plan is not valid JSON. Hive's EXPLAIN FORMATTED output is expected.";
+export const HIVE_PLAN_NO_PLAN_MESSAGE =
+ "The query plan has no CBO plan to draw. Hive states one only when its cost-based optimizer planned the statement.";
+
+function optionalNumber(value: unknown): number | undefined {
+ if (typeof value === "number" && Number.isFinite(value)) return value;
+ if (typeof value === "string" && value.trim()) {
+ const parsed = Number(value);
+ if (Number.isFinite(parsed)) return parsed;
+ }
+ return undefined;
+}
+
+function stringValue(value: unknown): string | undefined {
+ return typeof value === "string" && value.trim() ? value : undefined;
+}
+
+function isScalar(value: unknown): boolean {
+ return (
+ typeof value === "string" ||
+ typeof value === "number" ||
+ typeof value === "boolean"
+ );
+}
+
+/**
+ * A value worth putting on a card. Calcite writes a condition, an expression
+ * and an aggregate call as trees of operators and operands, which are the
+ * query's own syntax turned inside out; the scalars beside them are what reads
+ * as a fact about the operator.
+ */
+function scalarValue(value: unknown): string | undefined {
+ if (isScalar(value)) return String(value);
+ if (Array.isArray(value) && value.length > 0 && value.every(isScalar)) {
+ return value.map((entry) => String(entry)).join(", ");
+ }
+ return undefined;
+}
+
+/** The name of the operator or function an expression applies. */
+function operatorName(value: unknown): string | undefined {
+ if (!isJsonRecord(value)) return undefined;
+ const named = isJsonRecord(value.op) ? value.op : value.agg;
+ return isJsonRecord(named) ? stringValue(named.name) : undefined;
+}
+
+/**
+ * The table this operator reads. Hive writes it as the parts of its qualified
+ * name, which for a table in a database is the database and the table.
+ */
+function toRelation(raw: JsonRecord): PlanRelation | undefined {
+ if (!Array.isArray(raw.table)) return undefined;
+ const parts = raw.table
+ .map((part) => stringValue(part))
+ .filter((part): part is string => part !== undefined);
+ if (parts.length === 0) return undefined;
+ const table = parts[parts.length - 1];
+ return parts.length > 1 ? { database: parts[0], table } : { table };
+}
+
+/** The table the operator reads, with the alias the statement gave it. */
+function tableSubject(raw: JsonRecord): string | undefined {
+ const relation = toRelation(raw);
+ if (!relation) return undefined;
+ const qualified = relation.database
+ ? `${relation.database}.${relation.table}`
+ : relation.table;
+ const alias = stringValue(raw["table:alias"]);
+ return alias && alias !== relation.table
+ ? `${qualified} ${alias}`
+ : qualified;
+}
+
+/**
+ * What the operator does, for its card: the table it reads, or else the
+ * operator its condition applies, the columns it projects, or the aggregate it
+ * computes.
+ */
+function toSubject(raw: JsonRecord): string | undefined {
+ const table = tableSubject(raw);
+ if (table) return table;
+ const condition = operatorName(raw.condition);
+ if (condition) return condition;
+ const aggregates = Array.isArray(raw.aggs)
+ ? raw.aggs
+ .map((aggregate) => operatorName(aggregate))
+ .filter((name): name is string => name !== undefined)
+ : [];
+ if (aggregates.length > 0) return aggregates.join(", ");
+ return scalarValue(raw.fields);
+}
+
+function toProperties(raw: JsonRecord): PlanProperty[] {
+ const properties: PlanProperty[] = [];
+ // The id Calcite gives the operator, which its inputs refer to.
+ const id = stringValue(raw.id);
+ if (id) addPlanProperty(properties, "Operator", id);
+ for (const [key, value] of Object.entries(raw)) {
+ if (PROMOTED_KEYS.has(key)) continue;
+ const scalar = scalarValue(value);
+ if (scalar !== undefined) {
+ addPlanProperty(properties, planLabel(key), scalar);
+ continue;
+ }
+ // The column list is worth its length alone; the names are on the columns
+ // the operator projects.
+ if (key === "rowType" && Array.isArray(value)) {
+ addPlanProperty(properties, "Columns", String(value.length));
+ }
+ }
+ const condition = operatorName(raw.condition);
+ if (condition) addPlanProperty(properties, "Condition", condition);
+ return properties;
+}
+
+/**
+ * Which operators each operator reads, as positions in the list.
+ *
+ * Calcite leaves `inputs` out when an operator reads the one declared before
+ * it, writes `[]` on a leaf, and names them where there is a choice.
+ */
+function inputPositions(rels: JsonRecord[]): number[][] {
+ const positionOf = new Map<string, number>();
+ rels.forEach((rel, index) => {
+ const id = stringValue(rel.id);
+ if (id !== undefined && !positionOf.has(id)) positionOf.set(id, index);
+ });
+ return rels.map((raw, index) => {
+ if (!(INPUTS_KEY in raw)) return index > 0 ? [index - 1] : [];
+ if (!Array.isArray(raw[INPUTS_KEY])) return [];
+ return raw[INPUTS_KEY]
+ .map((input) => positionOf.get(String(input)))
+ .filter((at): at is number => at !== undefined);
+ });
+}
+
+/**
+ * @param seen - The operators on the path to this node. An operator that reads
+ * itself, directly or through another, would never finish; the rest of the
+ * plan still draws.
+ * @param count - The size budget, since an operator two others read is drawn
+ * under each of them.
+ */
+function toPlanNode(
+ index: number,
+ rels: JsonRecord[],
+ inputs: number[][],
+ id: string,
+ seen: Set<number>,
+ depth: number,
+ count: () => void
+): PlanNode {
+ checkPlanDepth(depth);
+ count();
+ const raw = rels[index];
+ const children: PlanNode[] = [];
+ for (const next of inputs[index]) {
+ if (seen.has(next)) continue;
+ seen.add(next);
+ children.push(
+ toPlanNode(
+ next,
+ rels,
+ inputs,
+ `${id}.${children.length}`,
+ seen,
+ depth + 1,
+ count
+ )
+ );
+ seen.delete(next);
+ }
+
+ const operator = stringValue(raw.relOp) ?? "";
+ return {
+ id,
+ nodeType: OPERATOR_CLASS.exec(operator)?.[1] ?? "Unknown",
+ subject: toSubject(raw),
+ relation: toRelation(raw),
+ rows: optionalNumber(raw.rowCount),
+ width: optionalNumber(raw.avgRowSize),
+ properties: toProperties(raw),
+ warnings: [],
+ children,
+ };
+}
+
+export function parseHivePlan(source: string): PlanParseResult {
+ const trimmed = source.trim();
+ if (!trimmed) {
+ return { ok: false, message: HIVE_PLAN_EMPTY_MESSAGE };
+ }
+
+ let parsed: unknown;
+ try {
+ parsed = JSON.parse(trimmed);
+ } catch {
+ return { ok: false, message: HIVE_PLAN_INVALID_JSON_MESSAGE };
+ }
+ if (!isJsonRecord(parsed)) {
+ return { ok: false, message: HIVE_PLAN_INVALID_JSON_MESSAGE };
+ }
+
+ // The plan Hive draws from is a JSON string within the JSON object.
+ const encoded = stringValue(parsed[PLAN_KEY]);
+ if (!encoded) {
+ return { ok: false, message: HIVE_PLAN_NO_PLAN_MESSAGE };
+ }
+ let plan: unknown;
+ try {
+ plan = JSON.parse(encoded);
+ } catch {
+ return { ok: false, message: HIVE_PLAN_INVALID_JSON_MESSAGE };
+ }
+ const rels =
+ isJsonRecord(plan) && Array.isArray(plan.rels)
+ ? plan.rels.filter(isJsonRecord)
+ : [];
+ if (rels.length === 0) {
+ return { ok: false, message: HIVE_PLAN_NO_PLAN_MESSAGE };
+ }
+
+ // The operator declared last returns the query's rows.
+ const root = rels.length - 1;
+ const inputs = inputPositions(rels);
+ const count = planSizeBudget();
+ return parseWithDepthLimit(() =>
+ toPlanNode(root, rels, inputs, "0", new Set([root]), 0, count)
+ );
+}
diff --git a/frontend/src/apps/explain-visualizer/plan-i18n.tsx b/frontend/src/apps/explain-visualizer/plan-i18n.tsx
index adb2555263..b7e7ffed27 100644
--- a/frontend/src/apps/explain-visualizer/plan-i18n.tsx
+++ b/frontend/src/apps/explain-visualizer/plan-i18n.tsx
@@ -36,6 +36,11 @@ const ENGLISH = {
"The query plan is not valid JSON. The diagram EXPLAIN (DISTSQL) encodes is expected.",
"error.cockroachdb-no-plan":
'The query plan JSON contains no "processors" to draw.',
+ "error.hive-empty": "Hive returned no query plan for this statement.",
+ "error.hive-invalid":
+ "The query plan is not valid JSON. Hive's EXPLAIN FORMATTED output is expected.",
+ "error.hive-no-plan":
+ "The query plan has no CBO plan to draw. Hive states one only when its cost-based optimizer planned the statement.",
"error.mongodb-empty": "MongoDB returned no query plan for this statement.",
"error.mongodb-invalid":
"The query plan is not valid JSON. MongoDB's explain() output is expected.",
@@ -66,6 +71,12 @@ const ENGLISH = {
"error.redshift-empty": "Redshift returned no query plan for this statement.",
"error.redshift-no-plan":
"The query plan has no operator in it: a Redshift plan states a cost for every one.",
+ "error.snowflake-empty":
+ "Snowflake returned no query plan for this statement.",
+ "error.snowflake-invalid":
+ "The query plan is not valid JSON. Snowflake's EXPLAIN USING JSON output is expected.",
+ "error.snowflake-no-plan":
+ "The query plan JSON contains no operation to start from.",
"error.spanner-emulator":
"Spanner returned no query plan for this statement. The Spanner emulator returns none for any statement, so explain it on a Spanner instance to see one.",
"error.spanner-empty": "Spanner returned no query plan for this statement.",
diff --git a/frontend/src/apps/explain-visualizer/plan-parsers.ts b/frontend/src/apps/explain-visualizer/plan-parsers.ts
index 839710496e..f08b593de2 100644
--- a/frontend/src/apps/explain-visualizer/plan-parsers.ts
+++ b/frontend/src/apps/explain-visualizer/plan-parsers.ts
@@ -2,6 +2,7 @@ import { Engine } from "@/types/proto-es/v1/common_pb";
import type { VisualizerEngine } from "@/utils/queryPlanEngines";
import { parseClickhousePlan } from "./clickhouse-plan";
import { parseCockroachdbPlan } from "./cockroachdb-plan";
+import { parseHivePlan } from "./hive-plan";
import { parseMongodbPlan } from "./mongodb-plan";
import { parseMssqlPlan } from "./mssql-plan";
import { parseMysqlPlan } from "./mysql-plan";
@@ -10,6 +11,7 @@ import { parseOraclePlan } from "./oracle-plan";
import type { PlanParseResult } from "./plan-model";
import { parsePostgresPlan } from "./postgres-plan";
import { parseRedshiftPlan } from "./redshift-plan";
+import { parseSnowflakePlan } from "./snowflake-plan";
import { parseSpannerPlan } from "./spanner-plan";
import { parseStarrocksPlan } from "./starrocks-plan";
import { parseTidbPlan } from "./tidb-plan";
@@ -43,6 +45,11 @@ const PARSERS: Record<VisualizerEngine, (source: string) => PlanParseResult> = {
// CockroachDB publishes no plan as a document; the server decodes the one it
// encodes in the diagram link EXPLAIN (DISTSQL) prints.
[Engine.COCKROACHDB]: parseCockroachdbPlan,
+ // Snowflake states each operation's parents rather than its children, so its
+ // parser turns those edges around.
+ [Engine.SNOWFLAKE]: parseSnowflakePlan,
+ // Hive answers with Calcite's own plan, as a JSON string within the JSON.
+ [Engine.HIVE]: parseHivePlan,
// The text plans drawn here, because none of these engines publishes
// anything else. StarRocks forked from Doris and their plans still agree on
// the fragments and the tree, so one parser reads both.
diff --git a/frontend/src/apps/explain-visualizer/snowflake-plan.test.ts b/frontend/src/apps/explain-visualizer/snowflake-plan.test.ts
new file mode 100644
index 0000000000..6805cf7ea5
--- /dev/null
+++ b/frontend/src/apps/explain-visualizer/snowflake-plan.test.ts
@@ -0,0 +1,205 @@
+import { describe, expect, test } from "vitest";
+import {
+ PLAN_FULL_TABLE_SCAN,
+ PLAN_TOO_DEEP_MESSAGE,
+ type PlanNode,
+ type PlanTree,
+} from "./plan-model";
+import {
+ parseSnowflakePlan,
+ SNOWFLAKE_PLAN_EMPTY_MESSAGE,
+ SNOWFLAKE_PLAN_INVALID_JSON_MESSAGE,
+ SNOWFLAKE_PLAN_NO_PLAN_MESSAGE,
+} from "./snowflake-plan";
+import innerJoin from "./test-data/snowflake/inner-join.json";
+
+/** One step holding `operations`, which is how Snowflake nests a plan. */
+const planOf = (operations: Record<string, unknown>[]): string =>
+ JSON.stringify({ Operations: [operations] });
+
+/** A chain of `depth` operations, which is what drives the depth limit. */
+const nestedPlan = (depth: number): string => {
+ const operations: Record<string, unknown>[] = [
+ { id: 0, operation: "Result" },
+ ];
+ for (let level = 1; level < depth; level += 1) {
+ operations.push({
+ id: level,
+ parentOperators: [level - 1],
+ operation: "Filter",
+ });
+ }
+ return planOf(operations);
+};
+
+const parse = (source: string): PlanTree => {
+ const result = parseSnowflakePlan(source);
+ if (!result.ok)
+ throw new Error(`expected a parsable plan: ${result.message}`);
+ return result.tree;
+};
+
+const parseFixture = (fixture: unknown): PlanTree =>
+ parse(JSON.stringify(fixture));
+
+const outline = (tree: PlanTree): string[] =>
+ tree.nodes.map(
+ (node) => `${node.id} ${node.nodeType} ${node.subject ?? "-"}`
+ );
+
+const propertyValue = (node: PlanNode, label: string): string | undefined =>
+ node.properties.find((property) => property.label === label)?.value;
+
+describe("parseSnowflakePlan", () => {
+ test("turns the parent ids around into a tree", () => {
+ // The plan states each operation's parents, so the join's two inputs are
+ // found by looking for the operations that name it.
+ const tree = parseFixture(innerJoin);
+ expect(outline(tree)).toEqual([
+ "0 Result Z1.ID, Z2.ID",
+ "0.0 InnerJoin joinKey: (Z2.ID = Z1.ID)",
+ "0.0.0 TableScan TESTDB.TEMPORARY_DOC_TEST.Z2",
+ "0.0.1 JoinFilter joinKey: (Z2.ID = Z1.ID)",
+ "0.0.1.0 TableScan TESTDB.TEMPORARY_DOC_TEST.Z1",
+ ]);
+ });
+
+ test("resolves a scan's table from the name Snowflake qualifies", () => {
+ const tree = parseFixture(innerJoin);
+ expect(tree.nodes[2].relation).toEqual({
+ database: "TESTDB",
+ schema: "TEMPORARY_DOC_TEST",
+ table: "Z2",
+ });
+ // An operation that reads no object has no table to look up.
+ expect(tree.root.relation).toBeUndefined();
+ });
+
+ test("keeps the pruning on the scan and the totals on the root", () => {
+ const tree = parseFixture(innerJoin);
+ expect(propertyValue(tree.nodes[2], "Partitions assigned")).toBe("1");
+ expect(propertyValue(tree.nodes[2], "Partitions total")).toBe("1");
+ expect(propertyValue(tree.nodes[2], "Bytes assigned")).toBe("512");
+ // GlobalStats is what the plan says about the query as a whole.
+ expect(propertyValue(tree.root, "Partitions total")).toBe("2");
+ expect(propertyValue(tree.root, "Bytes assigned")).toBe("1024");
+ // The operation id, so a reader can line the node up with Snowflake's own
+ // tabular plan.
+ expect(propertyValue(tree.root, "Operation")).toBe("0");
+ });
+
+ test("ranks nothing, since Snowflake estimates neither cost nor rows", () => {
+ const tree = parseFixture(innerJoin);
+ expect(tree.estimates.cost).toBe(false);
+ expect(tree.estimates.rows).toBe(false);
+ expect(tree.root.totalCost).toBeUndefined();
+ expect(tree.root.rows).toBeUndefined();
+ });
+
+ test("flags a scan assigned every partition of its table", () => {
+ const tree = parse(
+ planOf([
+ { id: 0, operation: "Result" },
+ {
+ id: 1,
+ parentOperators: [0],
+ operation: "TableScan",
+ objects: ["DB.PUBLIC.EVENTS"],
+ partitionsAssigned: 40,
+ partitionsTotal: 40,
+ },
+ ])
+ );
+ expect(tree.nodes[1].warnings).toEqual([PLAN_FULL_TABLE_SCAN]);
+ });
+
+ test("leaves a pruned scan, and a one-partition table, unflagged", () => {
+ const tree = parse(
+ planOf([
+ { id: 0, operation: "Result" },
+ {
+ id: 1,
+ parentOperators: [0],
+ operation: "TableScan",
+ objects: ["DB.PUBLIC.EVENTS"],
+ partitionsAssigned: 3,
+ partitionsTotal: 40,
+ },
+ {
+ id: 2,
+ parentOperators: [0],
+ operation: "TableScan",
+ objects: ["DB.PUBLIC.SMALL"],
+ partitionsAssigned: 1,
+ partitionsTotal: 1,
+ },
+ ])
+ );
+ expect(tree.nodes[1].warnings).toEqual([]);
+ expect(tree.nodes[2].warnings).toEqual([]);
+ });
+
+ test("draws the last step of a plan compiled into several", () => {
+ const tree = parse(
+ JSON.stringify({
+ Operations: [
+ [{ id: 0, operation: "Result", expressions: ["first step"] }],
+ [{ id: 0, operation: "Result", expressions: ["last step"] }],
+ ],
+ })
+ );
+ expect(tree.root.subject).toBe("last step");
+ expect(propertyValue(tree.root, "Steps")).toBe("2");
+ });
+
+ test("says so when there is no operation to start from", () => {
+ expect(parseSnowflakePlan("")).toEqual({
+ ok: false,
+ message: SNOWFLAKE_PLAN_EMPTY_MESSAGE,
+ });
+ expect(parseSnowflakePlan("not json")).toEqual({
+ ok: false,
+ message: SNOWFLAKE_PLAN_INVALID_JSON_MESSAGE,
+ });
+ expect(parseSnowflakePlan("[]")).toEqual({
+ ok: false,
+ message: SNOWFLAKE_PLAN_INVALID_JSON_MESSAGE,
+ });
+ expect(parseSnowflakePlan(JSON.stringify({ Operations: [] }))).toEqual({
+ ok: false,
+ message: SNOWFLAKE_PLAN_NO_PLAN_MESSAGE,
+ });
+ // Every operation naming a parent means there is no root to draw.
+ expect(
+ parseSnowflakePlan(
+ planOf([
+ { id: 0, parentOperators: [1], operation: "Result" },
+ { id: 1, parentOperators: [0], operation: "InnerJoin" },
+ ])
+ )
+ ).toEqual({ ok: false, message: SNOWFLAKE_PLAN_NO_PLAN_MESSAGE });
+ });
+
+ test("stops at an operation that reaches itself", () => {
+ // A cycle below the root would never finish; the rest still draws.
+ const tree = parse(
+ planOf([
+ { id: 0, operation: "Result" },
+ { id: 1, parentOperators: [0, 2], operation: "InnerJoin" },
+ { id: 2, parentOperators: [1], operation: "JoinFilter" },
+ ])
+ );
+ expect(outline(tree)).toEqual([
+ "0 Result -",
+ "0.0 InnerJoin -",
+ "0.0.0 JoinFilter -",
+ ]);
+ });
+
+ test("refuses a plan deeper than the viewer draws", () => {
+ expect(parseSnowflakePlan(nestedPlan(600))).toEqual({
+ ok: false,
+ message: PLAN_TOO_DEEP_MESSAGE,
+ });
+ });
+});
diff --git a/frontend/src/apps/explain-visualizer/snowflake-plan.ts b/frontend/src/apps/explain-visualizer/snowflake-plan.ts
new file mode 100644
index 0000000000..c49c0bf280
--- /dev/null
+++ b/frontend/src/apps/explain-visualizer/snowflake-plan.ts
@@ -0,0 +1,276 @@
+import {
+ addPlanProperty,
+ checkPlanDepth,
+ isJsonRecord,
+ type JsonRecord,
+ PLAN_FULL_TABLE_SCAN,
+ type PlanNode,
+ type PlanParseResult,
+ type PlanProperty,
+ type PlanRelation,
+ type PlanWarning,
+ parseWithDepthLimit,
+ planLabel,
+ planSizeBudget,
+} from "./plan-model";
+
+/**
+ * Maps `EXPLAIN USING JSON` output onto the engine-neutral plan model.
+ *
+ * Snowflake states each operation with the ids of its parents rather than its
+ * children, so the tree is those edges turned around. The operation that names
+ * no parent is the root: the `Result` that returns the query's rows.
+ *
+ * It estimates neither cost nor rows. What it states instead is how much of
+ * each table the query would read — the micro-partitions assigned out of the
+ * table's total, and the bytes they hold — which is what a Snowflake plan is
+ * read for. Those numbers stay on the node and nothing is ranked by them: only
+ * a scan reports them, so a ranking would weigh scans against parents that
+ * report nothing.
+ */
+
+const PARENTS_KEY = "parentOperators";
+
+/** Keys the model promotes to typed fields, so the property list drops them. */
+const PROMOTED_KEYS = new Set(["id", "operation", "objects", PARENTS_KEY]);
+
+/** The operation that reads a table, and the only one that reports pruning. */
+const TABLE_SCAN = "TableScan";
+
+/** Snowflake writes an object as `database.schema.name`. */
+const QUALIFIED_OBJECT = /^([^".]+)\.([^".]+)\.([^".]+)$/;
+
+export const SNOWFLAKE_PLAN_EMPTY_MESSAGE =
+ "Snowflake returned no query plan for this statement.";
+export const SNOWFLAKE_PLAN_INVALID_JSON_MESSAGE =
+ "The query plan is not valid JSON. Snowflake's EXPLAIN USING JSON output is expected.";
+export const SNOWFLAKE_PLAN_NO_PLAN_MESSAGE =
+ "The query plan JSON contains no operation to start from.";
+
+function optionalNumber(value: unknown): number | undefined {
+ if (typeof value === "number" && Number.isFinite(value)) return value;
+ if (typeof value === "string" && value.trim()) {
+ const parsed = Number(value);
+ if (Number.isFinite(parsed)) return parsed;
+ }
+ return undefined;
+}
+
+function stringValue(value: unknown): string | undefined {
+ return typeof value === "string" && value.trim() ? value : undefined;
+}
+
+function formatValue(value: unknown): string {
+ if (value === null || value === undefined) return "";
+ if (typeof value === "string") return value;
+ if (typeof value === "number" || typeof value === "boolean") {
+ return String(value);
+ }
+ if (Array.isArray(value)) {
+ return value.map((entry) => formatValue(entry)).join(", ");
+ }
+ return JSON.stringify(value);
+}
+
+/** The operation's id as the plan writes it, which its children refer to. */
+function operationID(raw: JsonRecord): string | undefined {
+ const id = optionalNumber(raw.id);
+ return id === undefined ? stringValue(raw.id) : String(id);
+}
+
+function parentIDs(raw: JsonRecord): string[] {
+ if (!Array.isArray(raw[PARENTS_KEY])) return [];
+ return raw[PARENTS_KEY]
+ .map((parent) => {
+ const id = optionalNumber(parent);
+ return id === undefined ? stringValue(parent) : String(id);
+ })
+ .filter((id): id is string => id !== undefined);
+}
+
+/** The first object the operation names, which for a scan is its table. */
+function firstObject(raw: JsonRecord): string | undefined {
+ if (Array.isArray(raw.objects)) {
+ for (const object of raw.objects) {
+ const name = stringValue(object);
+ if (name) return name;
+ }
+ return undefined;
+ }
+ return stringValue(raw.objects);
+}
+
+/**
+ * The table the operation reads. Snowflake qualifies an object fully, so a
+ * node answers a lookup without guessing the database or the schema; a name
+ * written any other way — a quoted identifier holding a dot, a stage — stays on
+ * the card as the subject alone.
+ */
+function toRelation(raw: JsonRecord): PlanRelation | undefined {
+ const object = firstObject(raw);
+ const qualified = object ? QUALIFIED_OBJECT.exec(object) : null;
+ if (!qualified) return undefined;
+ return { database: qualified[1], schema: qualified[2], table: qualified[3] };
+}
+
+function toProperties(raw: JsonRecord): PlanProperty[] {
+ const properties: PlanProperty[] = [];
+ // The id Snowflake's own tabular plan prints for this operation, which is
+ // what a reader comparing the two has in front of them.
+ const id = operationID(raw);
+ if (id !== undefined) addPlanProperty(properties, "Operation", id);
+ for (const [key, value] of Object.entries(raw)) {
+ if (PROMOTED_KEYS.has(key)) continue;
+ addPlanProperty(properties, planLabel(key), formatValue(value));
+ }
+ return properties;
+}
+
+/**
+ * A scan that was assigned every micro-partition the table has read all of it.
+ * A table of one partition is not one a reader can improve on, as in the other
+ * parsers.
+ */
+function toWarnings(raw: JsonRecord): PlanWarning[] {
+ if (stringValue(raw.operation) !== TABLE_SCAN) return [];
+ const total = optionalNumber(raw.partitionsTotal);
+ const assigned = optionalNumber(raw.partitionsAssigned);
+ if (total === undefined || assigned === undefined) return [];
+ return total > 1 && assigned >= total ? [PLAN_FULL_TABLE_SCAN] : [];
+}
+
+/**
+ * @param seen - The operations on the path to this node. An operation that
+ * reaches itself through its parents would never finish; the rest of the plan
+ * still draws.
+ * @param count - The size budget, since an operation named by two parents is
+ * drawn under each of them.
+ */
+function toPlanNode(
+ raw: JsonRecord,
+ children: Map<string, JsonRecord[]>,
+ id: string,
+ seen: Set<string>,
+ depth: number,
+ count: () => void
+): PlanNode {
+ checkPlanDepth(depth);
+ count();
+ const operation = operationID(raw);
+ const own = operation ? (children.get(operation) ?? []) : [];
+ const built: PlanNode[] = [];
+ for (const child of own) {
+ const childID = operationID(child);
+ if (childID !== undefined && seen.has(childID)) continue;
+ if (childID !== undefined) seen.add(childID);
+ built.push(
+ toPlanNode(
+ child,
+ children,
+ `${id}.${built.length}`,
+ seen,
+ depth + 1,
+ count
+ )
+ );
+ if (childID !== undefined) seen.delete(childID);
+ }
+
+ // An operation that names no object says what it does instead, which is the
+ // join keys on a join and the projected columns on a result.
+ const expressions = formatValue(raw.expressions);
+ return {
+ id,
+ nodeType: stringValue(raw.operation) ?? "Unknown",
+ subject: firstObject(raw) ?? (expressions || undefined),
+ relation: toRelation(raw),
+ properties: toProperties(raw),
+ warnings: toWarnings(raw),
+ children: built,
+ };
+}
+
+/** The operations of the step this plan is drawn from, and how many there are. */
+function stepOperations(parsed: JsonRecord): {
+ operations: JsonRecord[];
+ steps: number;
+} {
+ const steps = Array.isArray(parsed.Operations)
+ ? parsed.Operations.filter(
+ (step): step is unknown[] => Array.isArray(step) && step.length > 0
+ ).map((step) => step.filter(isJsonRecord))
+ : [];
+ // Snowflake compiles most statements into one step. Where it makes several,
+ // the last is the one that returns the query's rows, and the root's Steps
+ // property says how many there were.
+ return { operations: steps[steps.length - 1] ?? [], steps: steps.length };
+}
+
+export function parseSnowflakePlan(source: string): PlanParseResult {
+ const trimmed = source.trim();
+ if (!trimmed) {
+ return { ok: false, message: SNOWFLAKE_PLAN_EMPTY_MESSAGE };
+ }
+
+ let parsed: unknown;
+ try {
+ parsed = JSON.parse(trimmed);
+ } catch {
+ return { ok: false, message: SNOWFLAKE_PLAN_INVALID_JSON_MESSAGE };
+ }
+ if (!isJsonRecord(parsed)) {
+ return { ok: false, message: SNOWFLAKE_PLAN_INVALID_JSON_MESSAGE };
+ }
+
+ const { operations, steps } = stepOperations(parsed);
+ const children = new Map<string, JsonRecord[]>();
+ for (const operation of operations) {
+ for (const parent of parentIDs(operation)) {
+ const siblings = children.get(parent);
+ if (siblings) siblings.push(operation);
+ else children.set(parent, [operation]);
+ }
+ }
+ // The operation that names no parent returns the query's rows. A plan whose
+ // operations all name one — which would mean a cycle — has no root to draw.
+ const root = operations.find(
+ (operation) => parentIDs(operation).length === 0
+ );
+ if (!root) {
+ return { ok: false, message: SNOWFLAKE_PLAN_NO_PLAN_MESSAGE };
+ }
+
+ const count = planSizeBudget();
+ const rootID = operationID(root);
+ const result = parseWithDepthLimit(() =>
+ toPlanNode(
+ root,
+ children,
+ "0",
+ new Set(rootID === undefined ? [] : [rootID]),
+ 0,
+ count
+ )
+ );
+ if (!result.ok) return result;
+
+ // What the plan says about the query as a whole: the partitions it would
+ // read of every table together, and the step count where there was more than
+ // one. Both belong on the root, which is the query's own node.
+ const properties = [...result.tree.root.properties];
+ if (isJsonRecord(parsed.GlobalStats)) {
+ for (const [key, value] of Object.entries(parsed.GlobalStats)) {
+ addPlanProperty(properties, planLabel(key), formatValue(value));
+ }
+ }
+ if (steps > 1) addPlanProperty(properties, "Steps", String(steps));
+ const withGlobals = { ...result.tree.root, properties };
+ return {
+ ok: true,
+ tree: {
+ ...result.tree,
+ root: withGlobals,
+ nodes: [withGlobals, ...result.tree.nodes.slice(1)],
+ },
+ };
+}
diff --git a/frontend/src/apps/explain-visualizer/test-data/README.md b/frontend/src/apps/explain-visualizer/test-data/README.md
index 4785b2b669..1429da06b0 100644
--- a/frontend/src/apps/explain-visualizer/test-data/README.md
+++ b/frontend/src/apps/explain-visualizer/test-data/README.md
@@ -326,3 +326,40 @@ as it does every JSON file here.
| `filter-limit.json` | `filter.input.json` | Global and local limits, a seek condition |
| `scalar-subquery.json` | `scalar_subquery_with_filter_scan.input.json` | A scalar subquery with its own aggregates |
| `nested-array-subqueries.json` | `array_subqueries_with_compute_struct.input.json` | An array subquery inside another |
+
+## `snowflake/`
+
+`EXPLAIN USING JSON` output as Snowflake publishes it in
+[its EXPLAIN documentation](https://docs.snowflake.com/en/sql-reference/sql/explain)
+— the one fixture here not captured through the driver, because Snowflake runs
+nowhere but Snowflake. What the driver hands over is the same single JSON value,
+the one cell the statement returns. Snowflake estimates neither cost nor rows;
+what it states is how much of each table the query would read.
+
+| File | Shape it covers |
+| --- | --- |
+| `inner-join.json` | A join and its filter over two scans, each reporting the partitions and bytes assigned to it, with the query's totals in `GlobalStats` |
+
+To add one, run `EXPLAIN USING JSON <statement>` on a Snowflake warehouse and
+keep the cell verbatim. The cases a published plan does not show — a scan
+assigned every partition of its table, a statement compiled into several steps —
+are written inline in the test, which is where a plan no server emitted belongs.
+
+## `hive/`
+
+`EXPLAIN FORMATTED` output from Hive 4.0.0, HiveServer2 with its embedded
+metastore, against `customers` and `orders`. The repository's formatter indents
+the outer object; the plan the parser reads stays one escaped line within it,
+the `CBOPlan` *string*, which is how Hive answers. It states that string only
+where its cost-based optimizer planned the statement.
+
+| File | Shape it covers |
+| --- | --- |
+| `single-scan.json` | A scan under a filter under a project — the chain Calcite writes by leaving `inputs` out |
+| `join-aggregate.json` | A join naming both of its inputs, under an aggregate, on tables nothing had analyzed |
+| `analyzed-join.json` | The same query once the tables held rows and `ANALYZE TABLE … COMPUTE STATISTICS FOR COLUMNS` had run, so every operator states rows and the scans state a row width |
+| `union-all.json` | A union reading two branches |
+| `order-limit.json` | A sort with a fetch |
+| `no-cbo-plan.json` | `hive.cbo.enable=false`: the Tez stages alone, with no `CBOPlan`, which the viewer shows as text |
+
+To add one, `EXPLAIN FORMATTED` through the same client.
diff --git a/frontend/src/apps/explain-visualizer/test-data/hive/analyzed-join.json b/frontend/src/apps/explain-visualizer/test-data/hive/analyzed-join.json
new file mode 100644
index 0000000000..609ffcf9a4
--- /dev/null
+++ b/frontend/src/apps/explain-visualizer/test-data/hive/analyzed-join.json
@@ -0,0 +1,186 @@
+{
+ "CBOPlan": "{\n \"rels\": [\n {\n \"id\": \"0\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableScan\",\n \"table\": [\n \"default\",\n \"customers_d\"\n ],\n \"table:alias\": \"c\",\n \"inputs\": [],\n \"rowCount\": 5.0,\n \"avgRowSize\": 9.4,\n \"rowType\": [\n {\n \"type\": \"INTEGER\",\n \"nullable\": true,\n \"name\": \"id\"\n },\n {\n \"type\": \"VARCHAR\",\n \"nullable\": true,\n \"precision\": 2147483647,\n \"name\": \"name\"\n },\n {\n \"type\": \"VARCHAR\",\n \"nullable\": true,\n \"precision\": 2147483647,\n \"name\": \"city\"\n },\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"BLOCK__OFFSET__INSIDE__FILE\"\n },\n {\n \"type\": \"VARCHAR\",\n \"nullable\": true,\n \"precision\": 2147483647,\n \"name\": \"INPUT__FILE__NAME\"\n },\n {\n \"fields\": [\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"writeid\"\n },\n {\n \"type\": \"INTEGER\",\n \"nullable\": true,\n \"name\": \"bucketid\"\n },\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"rowid\"\n }\n ],\n \"name\": \"ROW__ID\"\n },\n {\n \"type\": \"BOOLEAN\",\n \"nullable\": true,\n \"name\": \"ROW__IS__DELETED\"\n }\n ],\n \"colStats\": [\n {\n \"name\": \"id\",\n \"ndv\": 5,\n \"minValue\": 1,\n \"maxValue\": 5\n },\n {\n \"name\": \"city\",\n \"ndv\": 3\n },\n {\n \"name\": \"name\",\n \"ndv\": 5\n }\n ]\n },\n {\n \"id\": \"1\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveFilter\",\n \"condition\": {\n \"op\": {\n \"name\": \"AND\",\n \"kind\": \"AND\",\n \"syntax\": \"BINARY\"\n },\n \"operands\": [\n {\n \"op\": {\n \"name\": \"=\",\n \"kind\": \"EQUALS\",\n \"syntax\": \"BINARY\"\n },\n \"operands\": [\n {\n \"input\": 2,\n \"name\": \"$2\"\n },\n {\n \"literal\": \"berlin\",\n \"type\": {\n \"type\": \"VARCHAR\",\n \"nullable\": false,\n \"precision\": 2147483647\n }\n }\n ]\n },\n {\n \"op\": {\n \"name\": \"IS NOT NULL\",\n \"kind\": \"IS_NOT_NULL\",\n \"syntax\": \"POSTFIX\"\n },\n \"operands\": [\n {\n \"input\": 0,\n \"name\": \"$0\"\n }\n ]\n }\n ]\n },\n \"rowCount\": 1.6666666666666665\n },\n {\n \"id\": \"2\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject\",\n \"fields\": [\n \"id\"\n ],\n \"exprs\": [\n {\n \"input\": 0,\n \"name\": \"$0\"\n }\n ],\n \"rowCount\": 1.6666666666666665\n },\n {\n \"id\": \"3\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableScan\",\n \"table\": [\n \"default\",\n \"orders_d\"\n ],\n \"table:alias\": \"o\",\n \"inputs\": [],\n \"rowCount\": 6.0,\n \"avgRowSize\": 4.0,\n \"rowType\": [\n {\n \"type\": \"INTEGER\",\n \"nullable\": true,\n \"name\": \"id\"\n },\n {\n \"type\": \"INTEGER\",\n \"nullable\": true,\n \"name\": \"customer_id\"\n },\n {\n \"type\": \"DOUBLE\",\n \"nullable\": true,\n \"name\": \"total\"\n },\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"BLOCK__OFFSET__INSIDE__FILE\"\n },\n {\n \"type\": \"VARCHAR\",\n \"nullable\": true,\n \"precision\": 2147483647,\n \"name\": \"INPUT__FILE__NAME\"\n },\n {\n \"fields\": [\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"writeid\"\n },\n {\n \"type\": \"INTEGER\",\n \"nullable\": true,\n \"name\": \"bucketid\"\n },\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"rowid\"\n }\n ],\n \"name\": \"ROW__ID\"\n },\n {\n \"type\": \"BOOLEAN\",\n \"nullable\": true,\n \"name\": \"ROW__IS__DELETED\"\n }\n ],\n \"colStats\": [\n {\n \"name\": \"customer_id\",\n \"ndv\": 4,\n \"minValue\": 1,\n \"maxValue\": 4\n },\n {\n \"name\": \"id\",\n \"ndv\": 6,\n \"minValue\": 1,\n \"maxValue\": 6\n },\n {\n \"name\": \"total\",\n \"ndv\": 6,\n \"minValue\": 5.25,\n \"maxValue\": 99.9\n }\n ]\n },\n {\n \"id\": \"4\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveFilter\",\n \"condition\": {\n \"op\": {\n \"name\": \"IS NOT NULL\",\n \"kind\": \"IS_NOT_NULL\",\n \"syntax\": \"POSTFIX\"\n },\n \"operands\": [\n {\n \"input\": 1,\n \"name\": \"$1\"\n }\n ]\n },\n \"rowCount\": 6.0\n },\n {\n \"id\": \"5\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject\",\n \"fields\": [\n \"customer_id\"\n ],\n \"exprs\": [\n {\n \"input\": 1,\n \"name\": \"$1\"\n }\n ],\n \"rowCount\": 6.0\n },\n {\n \"id\": \"6\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveJoin\",\n \"condition\": {\n \"op\": {\n \"name\": \"=\",\n \"kind\": \"EQUALS\",\n \"syntax\": \"BINARY\"\n },\n \"operands\": [\n {\n \"input\": 1,\n \"name\": \"$1\"\n },\n {\n \"input\": 0,\n \"name\": \"$0\"\n }\n ]\n },\n \"joinType\": \"inner\",\n \"algorithm\": \"none\",\n \"cost\": \"not available\",\n \"inputs\": [\n \"2\",\n \"5\"\n ],\n \"rowCount\": 2.0\n },\n {\n \"id\": \"7\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject\",\n \"fields\": [\n \"$f0\"\n ],\n \"exprs\": [\n {\n \"literal\": true,\n \"type\": {\n \"type\": \"BOOLEAN\",\n \"nullable\": false\n }\n }\n ],\n \"rowCount\": 2.0\n },\n {\n \"id\": \"8\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveAggregate\",\n \"group\": [\n 0\n ],\n \"aggs\": [\n {\n \"agg\": {\n \"name\": \"count\",\n \"kind\": \"COUNT\",\n \"syntax\": \"FUNCTION_STAR\"\n },\n \"type\": {\n \"type\": \"BIGINT\",\n \"nullable\": true\n },\n \"distinct\": false,\n \"operands\": [],\n \"name\": null\n }\n ],\n \"rowCount\": 1.0\n },\n {\n \"id\": \"9\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject\",\n \"fields\": [\n \"city\",\n \"_o__c1\"\n ],\n \"exprs\": [\n {\n \"op\": {\n \"name\": \"CAST\",\n \"kind\": \"CAST\",\n \"syntax\": \"SPECIAL\"\n },\n \"operands\": [\n {\n \"literal\": \"berlin\",\n \"type\": {\n \"type\": \"VARCHAR\",\n \"nullable\": false,\n \"precision\": 2147483647\n }\n }\n ],\n \"type\": {\n \"type\": \"VARCHAR\",\n \"nullable\": true,\n \"precision\": 2147483647\n }\n },\n {\n \"input\": 1,\n \"name\": \"$1\"\n }\n ],\n \"rowCount\": 1.0\n }\n ]\n}",
+ "optimizedSQL": "SELECT CAST('berlin' AS STRING) AS `city`, COUNT(*) AS `_o__c1`\nFROM (SELECT `id`\nFROM `default`.`customers_d`\nWHERE `city` = 'berlin' AND `id` IS NOT NULL) AS `t0`\nINNER JOIN (SELECT `customer_id`\nFROM `default`.`orders_d`\nWHERE `customer_id` IS NOT NULL) AS `t2` ON `t0`.`id` = `t2`.`customer_id`\nGROUP BY TRUE",
+ "cboInfo": "Plan optimized by CBO.",
+ "STAGE DEPENDENCIES": {
+ "Stage-1": { "ROOT STAGE": "TRUE" },
+ "Stage-0": { "DEPENDENT STAGES": "Stage-1" }
+ },
+ "STAGE PLANS": {
+ "Stage-1": {
+ "Tez": {
+ "DagId:": "hive_20261027081116_6ee3d16f-5201-4d26-9dd6-70602318e5e9:8",
+ "Edges:": {
+ "Map 2": { "parent": "Map 1", "type": "BROADCAST_EDGE" },
+ "Reducer 3": { "parent": "Map 2", "type": "SIMPLE_EDGE" }
+ },
+ "DagName:": "hive_20261027081116_6ee3d16f-5201-4d26-9dd6-70602318e5e9:8",
+ "Vertices:": {
+ "Map 1": {
+ "Map Operator Tree:": [
+ {
+ "TableScan": {
+ "alias:": "c",
+ "columns:": ["id", "city"],
+ "database:": "default",
+ "filterExpr:": "((city = 'berlin') and id is not null) (type: boolean)",
+ "Statistics:": "Num rows: 5 Data size: 465 Basic stats: COMPLETE Column stats: COMPLETE",
+ "table:": "customers_d",
+ "isTempTable:": "false",
+ "OperatorId:": "TS_0",
+ "children": {
+ "Filter Operator": {
+ "predicate:": "((city = 'berlin') and id is not null) (type: boolean)",
+ "Statistics:": "Num rows: 2 Data size: 186 Basic stats: COMPLETE Column stats: COMPLETE",
+ "OperatorId:": "FIL_22",
+ "children": {
+ "Select Operator": {
+ "expressions:": "id (type: int)",
+ "columnExprMap:": { "_col0": "id" },
+ "outputColumnNames:": ["_col0"],
+ "Statistics:": "Num rows: 2 Data size: 8 Basic stats: COMPLETE Column stats: COMPLETE",
+ "OperatorId:": "SEL_23",
+ "children": {
+ "Reduce Output Operator": {
+ "columnExprMap:": {
+ "KEY.reducesinkkey0": "_col0"
+ },
+ "key expressions:": "_col0 (type: int)",
+ "null sort order:": "z",
+ "sort order:": "+",
+ "Map-reduce partition columns:": "_col0 (type: int)",
+ "Statistics:": "Num rows: 2 Data size: 8 Basic stats: COMPLETE Column stats: COMPLETE",
+ "OperatorId:": "RS_24",
+ "outputname:": "Map 2",
+ "outputOperator:": ["TS_3"]
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ ],
+ "Execution mode:": "vectorized"
+ },
+ "Map 2": {
+ "Map Operator Tree:": [
+ {
+ "TableScan": {
+ "alias:": "o",
+ "columns:": ["customer_id"],
+ "database:": "default",
+ "filterExpr:": "customer_id is not null (type: boolean)",
+ "Statistics:": "Num rows: 6 Data size: 24 Basic stats: COMPLETE Column stats: COMPLETE",
+ "table:": "orders_d",
+ "isTempTable:": "false",
+ "OperatorId:": "TS_3",
+ "children": {
+ "Filter Operator": {
+ "predicate:": "customer_id is not null (type: boolean)",
+ "Statistics:": "Num rows: 6 Data size: 24 Basic stats: COMPLETE Column stats: COMPLETE",
+ "OperatorId:": "FIL_25",
+ "children": {
+ "Select Operator": {
+ "expressions:": "customer_id (type: int)",
+ "columnExprMap:": { "_col0": "customer_id" },
+ "outputColumnNames:": ["_col0"],
+ "Statistics:": "Num rows: 6 Data size: 24 Basic stats: COMPLETE Column stats: COMPLETE",
+ "OperatorId:": "SEL_26",
+ "children": {
+ "Map Join Operator": {
+ "condition map:": [{ "": "Inner Join 0 to 1" }],
+ "keys:": {
+ "0": "_col0 (type: int)",
+ "1": "_col0 (type: int)"
+ },
+ "input vertices:": { "0": "Map 1" },
+ "Statistics:": "Num rows: 4 Data size: 32 Basic stats: COMPLETE Column stats: COMPLETE",
+ "OperatorId:": "MAPJOIN_27",
+ "children": {
+ "Group By Operator": {
+ "aggregations:": ["count()"],
+ "columnExprMap:": { "_col0": "true" },
+ "keys:": "true (type: boolean)",
+ "minReductionHashAggr:": "0.75",
+ "mode:": "hash",
+ "outputColumnNames:": ["_col0", "_col1"],
+ "Statistics:": "Num rows: 1 Data size: 12 Basic stats: COMPLETE Column stats: COMPLETE",
+ "OperatorId:": "GBY_28",
+ "children": {
+ "Reduce Output Operator": {
+ "columnExprMap:": {
+ "KEY._col0": "true",
+ "VALUE._col0": "_col1"
+ },
+ "key expressions:": "_col0 (type: boolean)",
+ "null sort order:": "z",
+ "sort order:": "+",
+ "Map-reduce partition columns:": "_col0 (type: boolean)",
+ "Statistics:": "Num rows: 1 Data size: 12 Basic stats: COMPLETE Column stats: COMPLETE",
+ "value expressions:": "_col1 (type: bigint)",
+ "OperatorId:": "RS_29",
+ "outputname:": "Reducer 3",
+ "outputOperator:": ["GBY_30"]
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ ],
+ "Execution mode:": "vectorized"
+ },
+ "Reducer 3": {
+ "Execution mode:": "vectorized",
+ "Reduce Operator Tree:": {
+ "Group By Operator": {
+ "aggregations:": ["count(VALUE._col0)"],
+ "columnExprMap:": { "_col0": "true" },
+ "keys:": "KEY._col0 (type: boolean)",
+ "mode:": "mergepartial",
+ "outputColumnNames:": ["_col0", "_col1"],
+ "Statistics:": "Num rows: 1 Data size: 12 Basic stats: COMPLETE Column stats: COMPLETE",
+ "OperatorId:": "GBY_30",
+ "children": {
+ "Select Operator": {
+ "expressions:": "'berlin' (type: string), _col1 (type: bigint)",
+ "columnExprMap:": { "_col0": "'berlin'", "_col1": "_col1" },
+ "outputColumnNames:": ["_col0", "_col1"],
+ "Statistics:": "Num rows: 1 Data size: 98 Basic stats: COMPLETE Column stats: COMPLETE",
+ "OperatorId:": "SEL_31",
+ "children": {
+ "File Output Operator": {
+ "compressed:": "false",
+ "Statistics:": "Num rows: 1 Data size: 98 Basic stats: COMPLETE Column stats: COMPLETE",
+ "table:": {
+ "input format:": "org.apache.hadoop.mapred.SequenceFileInputFormat",
+ "output format:": "org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat",
+ "serde:": "org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe"
+ },
+ "OperatorId:": "FS_32"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "Stage-0": {
+ "Fetch Operator": {
+ "limit:": "-1",
+ "Processor Tree:": { "ListSink": { "OperatorId:": "LIST_SINK_33" } }
+ }
+ }
+ }
+}
diff --git a/frontend/src/apps/explain-visualizer/test-data/hive/join-aggregate.json b/frontend/src/apps/explain-visualizer/test-data/hive/join-aggregate.json
new file mode 100644
index 0000000000..de389966fc
--- /dev/null
+++ b/frontend/src/apps/explain-visualizer/test-data/hive/join-aggregate.json
@@ -0,0 +1,186 @@
+{
+ "CBOPlan": "{\n \"rels\": [\n {\n \"id\": \"0\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableScan\",\n \"table\": [\n \"default\",\n \"customers\"\n ],\n \"table:alias\": \"c\",\n \"inputs\": [],\n \"rowCount\": 1.0,\n \"avgRowSize\": 104.0,\n \"rowType\": [\n {\n \"type\": \"INTEGER\",\n \"nullable\": true,\n \"name\": \"id\"\n },\n {\n \"type\": \"VARCHAR\",\n \"nullable\": true,\n \"precision\": 2147483647,\n \"name\": \"name\"\n },\n {\n \"type\": \"VARCHAR\",\n \"nullable\": true,\n \"precision\": 2147483647,\n \"name\": \"city\"\n },\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"BLOCK__OFFSET__INSIDE__FILE\"\n },\n {\n \"type\": \"VARCHAR\",\n \"nullable\": true,\n \"precision\": 2147483647,\n \"name\": \"INPUT__FILE__NAME\"\n },\n {\n \"fields\": [\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"writeid\"\n },\n {\n \"type\": \"INTEGER\",\n \"nullable\": true,\n \"name\": \"bucketid\"\n },\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"rowid\"\n }\n ],\n \"name\": \"ROW__ID\"\n },\n {\n \"type\": \"BOOLEAN\",\n \"nullable\": true,\n \"name\": \"ROW__IS__DELETED\"\n }\n ],\n \"colStats\": [\n {\n \"name\": \"id\",\n \"ndv\": 1,\n \"minValue\": -9223372036854775808,\n \"maxValue\": 9223372036854775807\n },\n {\n \"name\": \"city\",\n \"ndv\": 1\n },\n {\n \"name\": \"name\",\n \"ndv\": 1\n }\n ]\n },\n {\n \"id\": \"1\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveFilter\",\n \"condition\": {\n \"op\": {\n \"name\": \"AND\",\n \"kind\": \"AND\",\n \"syntax\": \"BINARY\"\n },\n \"operands\": [\n {\n \"op\": {\n \"name\": \"=\",\n \"kind\": \"EQUALS\",\n \"syntax\": \"BINARY\"\n },\n \"operands\": [\n {\n \"input\": 2,\n \"name\": \"$2\"\n },\n {\n \"literal\": \"berlin\",\n \"type\": {\n \"type\": \"VARCHAR\",\n \"nullable\": false,\n \"precision\": 2147483647\n }\n }\n ]\n },\n {\n \"op\": {\n \"name\": \"IS NOT NULL\",\n \"kind\": \"IS_NOT_NULL\",\n \"syntax\": \"POSTFIX\"\n },\n \"operands\": [\n {\n \"input\": 0,\n \"name\": \"$0\"\n }\n ]\n }\n ]\n },\n \"rowCount\": 1.0\n },\n {\n \"id\": \"2\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject\",\n \"fields\": [\n \"id\"\n ],\n \"exprs\": [\n {\n \"input\": 0,\n \"name\": \"$0\"\n }\n ],\n \"rowCount\": 1.0\n },\n {\n \"id\": \"3\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableScan\",\n \"table\": [\n \"default\",\n \"orders\"\n ],\n \"table:alias\": \"o\",\n \"inputs\": [],\n \"rowCount\": 1.0,\n \"avgRowSize\": 4.0,\n \"rowType\": [\n {\n \"type\": \"INTEGER\",\n \"nullable\": true,\n \"name\": \"id\"\n },\n {\n \"type\": \"INTEGER\",\n \"nullable\": true,\n \"name\": \"customer_id\"\n },\n {\n \"type\": \"DOUBLE\",\n \"nullable\": true,\n \"name\": \"total\"\n },\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"BLOCK__OFFSET__INSIDE__FILE\"\n },\n {\n \"type\": \"VARCHAR\",\n \"nullable\": true,\n \"precision\": 2147483647,\n \"name\": \"INPUT__FILE__NAME\"\n },\n {\n \"fields\": [\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"writeid\"\n },\n {\n \"type\": \"INTEGER\",\n \"nullable\": true,\n \"name\": \"bucketid\"\n },\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"rowid\"\n }\n ],\n \"name\": \"ROW__ID\"\n },\n {\n \"type\": \"BOOLEAN\",\n \"nullable\": true,\n \"name\": \"ROW__IS__DELETED\"\n }\n ],\n \"colStats\": [\n {\n \"name\": \"customer_id\",\n \"ndv\": 1,\n \"minValue\": -9223372036854775808,\n \"maxValue\": 9223372036854775807\n },\n {\n \"name\": \"id\",\n \"ndv\": 1,\n \"minValue\": -9223372036854775808,\n \"maxValue\": 9223372036854775807\n },\n {\n \"name\": \"total\",\n \"ndv\": 1,\n \"minValue\": 4.9E-324,\n \"maxValue\": 1.7976931348623157E308\n }\n ]\n },\n {\n \"id\": \"4\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveFilter\",\n \"condition\": {\n \"op\": {\n \"name\": \"IS NOT NULL\",\n \"kind\": \"IS_NOT_NULL\",\n \"syntax\": \"POSTFIX\"\n },\n \"operands\": [\n {\n \"input\": 1,\n \"name\": \"$1\"\n }\n ]\n },\n \"rowCount\": 1.0\n },\n {\n \"id\": \"5\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject\",\n \"fields\": [\n \"customer_id\"\n ],\n \"exprs\": [\n {\n \"input\": 1,\n \"name\": \"$1\"\n }\n ],\n \"rowCount\": 1.0\n },\n {\n \"id\": \"6\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveJoin\",\n \"condition\": {\n \"op\": {\n \"name\": \"=\",\n \"kind\": \"EQUALS\",\n \"syntax\": \"BINARY\"\n },\n \"operands\": [\n {\n \"input\": 1,\n \"name\": \"$1\"\n },\n {\n \"input\": 0,\n \"name\": \"$0\"\n }\n ]\n },\n \"joinType\": \"inner\",\n \"algorithm\": \"none\",\n \"cost\": \"not available\",\n \"inputs\": [\n \"2\",\n \"5\"\n ],\n \"rowCount\": 1.0\n },\n {\n \"id\": \"7\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject\",\n \"fields\": [\n \"$f0\"\n ],\n \"exprs\": [\n {\n \"literal\": true,\n \"type\": {\n \"type\": \"BOOLEAN\",\n \"nullable\": false\n }\n }\n ],\n \"rowCount\": 1.0\n },\n {\n \"id\": \"8\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveAggregate\",\n \"group\": [\n 0\n ],\n \"aggs\": [\n {\n \"agg\": {\n \"name\": \"count\",\n \"kind\": \"COUNT\",\n \"syntax\": \"FUNCTION_STAR\"\n },\n \"type\": {\n \"type\": \"BIGINT\",\n \"nullable\": true\n },\n \"distinct\": false,\n \"operands\": [],\n \"name\": null\n }\n ],\n \"rowCount\": 1.0\n },\n {\n \"id\": \"9\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject\",\n \"fields\": [\n \"city\",\n \"_o__c1\"\n ],\n \"exprs\": [\n {\n \"op\": {\n \"name\": \"CAST\",\n \"kind\": \"CAST\",\n \"syntax\": \"SPECIAL\"\n },\n \"operands\": [\n {\n \"literal\": \"berlin\",\n \"type\": {\n \"type\": \"VARCHAR\",\n \"nullable\": false,\n \"precision\": 2147483647\n }\n }\n ],\n \"type\": {\n \"type\": \"VARCHAR\",\n \"nullable\": true,\n \"precision\": 2147483647\n }\n },\n {\n \"input\": 1,\n \"name\": \"$1\"\n }\n ],\n \"rowCount\": 1.0\n }\n ]\n}",
+ "optimizedSQL": "SELECT CAST('berlin' AS STRING) AS `city`, COUNT(*) AS `_o__c1`\nFROM (SELECT `id`\nFROM `default`.`customers`\nWHERE `city` = 'berlin' AND `id` IS NOT NULL) AS `t0`\nINNER JOIN (SELECT `customer_id`\nFROM `default`.`orders`\nWHERE `customer_id` IS NOT NULL) AS `t2` ON `t0`.`id` = `t2`.`customer_id`\nGROUP BY TRUE",
+ "cboInfo": "Plan optimized by CBO.",
+ "STAGE DEPENDENCIES": {
+ "Stage-1": { "ROOT STAGE": "TRUE" },
+ "Stage-0": { "DEPENDENT STAGES": "Stage-1" }
+ },
+ "STAGE PLANS": {
+ "Stage-1": {
+ "Tez": {
+ "DagId:": "hive_20261027075644_968ddcfa-b536-49d8-80b8-aeea325f39a0:3",
+ "Edges:": {
+ "Map 1": { "parent": "Map 3", "type": "BROADCAST_EDGE" },
+ "Reducer 2": { "parent": "Map 1", "type": "SIMPLE_EDGE" }
+ },
+ "DagName:": "hive_20261027075644_968ddcfa-b536-49d8-80b8-aeea325f39a0:3",
+ "Vertices:": {
+ "Map 1": {
+ "Map Operator Tree:": [
+ {
+ "TableScan": {
+ "alias:": "c",
+ "columns:": ["id", "city"],
+ "database:": "default",
+ "filterExpr:": "((city = 'berlin') and id is not null) (type: boolean)",
+ "Statistics:": "Num rows: 1 Data size: 188 Basic stats: COMPLETE Column stats: NONE",
+ "table:": "customers",
+ "isTempTable:": "false",
+ "OperatorId:": "TS_0",
+ "children": {
+ "Filter Operator": {
+ "predicate:": "((city = 'berlin') and id is not null) (type: boolean)",
+ "Statistics:": "Num rows: 1 Data size: 188 Basic stats: COMPLETE Column stats: NONE",
+ "OperatorId:": "FIL_25",
+ "children": {
+ "Select Operator": {
+ "expressions:": "id (type: int)",
+ "columnExprMap:": { "_col0": "id" },
+ "outputColumnNames:": ["_col0"],
+ "Statistics:": "Num rows: 1 Data size: 188 Basic stats: COMPLETE Column stats: NONE",
+ "OperatorId:": "SEL_26",
+ "children": {
+ "Map Join Operator": {
+ "condition map:": [{ "": "Inner Join 0 to 1" }],
+ "keys:": {
+ "0": "_col0 (type: int)",
+ "1": "_col0 (type: int)"
+ },
+ "input vertices:": { "1": "Map 3" },
+ "Statistics:": "Num rows: 1 Data size: 206 Basic stats: COMPLETE Column stats: NONE",
+ "OperatorId:": "MAPJOIN_27",
+ "children": {
+ "Group By Operator": {
+ "aggregations:": ["count()"],
+ "columnExprMap:": { "_col0": "true" },
+ "keys:": "true (type: boolean)",
+ "minReductionHashAggr:": "0.99",
+ "mode:": "hash",
+ "outputColumnNames:": ["_col0", "_col1"],
+ "Statistics:": "Num rows: 1 Data size: 206 Basic stats: COMPLETE Column stats: NONE",
+ "OperatorId:": "GBY_28",
+ "children": {
+ "Reduce Output Operator": {
+ "columnExprMap:": {
+ "KEY._col0": "true",
+ "VALUE._col0": "_col1"
+ },
+ "key expressions:": "_col0 (type: boolean)",
+ "null sort order:": "z",
+ "sort order:": "+",
+ "Map-reduce partition columns:": "_col0 (type: boolean)",
+ "Statistics:": "Num rows: 1 Data size: 206 Basic stats: COMPLETE Column stats: NONE",
+ "value expressions:": "_col1 (type: bigint)",
+ "OperatorId:": "RS_29",
+ "outputname:": "Reducer 2",
+ "outputOperator:": ["GBY_30"]
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ ],
+ "Execution mode:": "vectorized"
+ },
+ "Map 3": {
+ "Map Operator Tree:": [
+ {
+ "TableScan": {
+ "alias:": "o",
+ "columns:": ["customer_id"],
+ "database:": "default",
+ "filterExpr:": "customer_id is not null (type: boolean)",
+ "Statistics:": "Num rows: 1 Data size: 4 Basic stats: COMPLETE Column stats: NONE",
+ "table:": "orders",
+ "isTempTable:": "false",
+ "OperatorId:": "TS_3",
+ "children": {
+ "Filter Operator": {
+ "predicate:": "customer_id is not null (type: boolean)",
+ "Statistics:": "Num rows: 1 Data size: 4 Basic stats: COMPLETE Column stats: NONE",
+ "OperatorId:": "FIL_22",
+ "children": {
+ "Select Operator": {
+ "expressions:": "customer_id (type: int)",
+ "columnExprMap:": { "_col0": "customer_id" },
+ "outputColumnNames:": ["_col0"],
+ "Statistics:": "Num rows: 1 Data size: 4 Basic stats: COMPLETE Column stats: NONE",
+ "OperatorId:": "SEL_23",
+ "children": {
+ "Reduce Output Operator": {
+ "columnExprMap:": {
+ "KEY.reducesinkkey0": "_col0"
+ },
+ "key expressions:": "_col0 (type: int)",
+ "null sort order:": "z",
+ "sort order:": "+",
+ "Map-reduce partition columns:": "_col0 (type: int)",
+ "Statistics:": "Num rows: 1 Data size: 4 Basic stats: COMPLETE Column stats: NONE",
+ "OperatorId:": "RS_24",
+ "outputname:": "Map 1",
+ "outputOperator:": ["TS_0"]
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ ],
+ "Execution mode:": "vectorized"
+ },
+ "Reducer 2": {
+ "Execution mode:": "vectorized",
+ "Reduce Operator Tree:": {
+ "Group By Operator": {
+ "aggregations:": ["count(VALUE._col0)"],
+ "columnExprMap:": { "_col0": "true" },
+ "keys:": "KEY._col0 (type: boolean)",
+ "mode:": "mergepartial",
+ "outputColumnNames:": ["_col0", "_col1"],
+ "Statistics:": "Num rows: 1 Data size: 206 Basic stats: COMPLETE Column stats: NONE",
+ "OperatorId:": "GBY_30",
+ "children": {
+ "Select Operator": {
+ "expressions:": "'berlin' (type: string), _col1 (type: bigint)",
+ "columnExprMap:": { "_col0": "'berlin'", "_col1": "_col1" },
+ "outputColumnNames:": ["_col0", "_col1"],
+ "Statistics:": "Num rows: 1 Data size: 206 Basic stats: COMPLETE Column stats: NONE",
+ "OperatorId:": "SEL_31",
+ "children": {
+ "File Output Operator": {
+ "compressed:": "false",
+ "Statistics:": "Num rows: 1 Data size: 206 Basic stats: COMPLETE Column stats: NONE",
+ "table:": {
+ "input format:": "org.apache.hadoop.mapred.SequenceFileInputFormat",
+ "output format:": "org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat",
+ "serde:": "org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe"
+ },
+ "OperatorId:": "FS_32"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "Stage-0": {
+ "Fetch Operator": {
+ "limit:": "-1",
+ "Processor Tree:": { "ListSink": { "OperatorId:": "LIST_SINK_33" } }
+ }
+ }
+ }
+}
diff --git a/frontend/src/apps/explain-visualizer/test-data/hive/no-cbo-plan.json b/frontend/src/apps/explain-visualizer/test-data/hive/no-cbo-plan.json
new file mode 100644
index 0000000000..ad4ef53e47
--- /dev/null
+++ b/frontend/src/apps/explain-visualizer/test-data/hive/no-cbo-plan.json
@@ -0,0 +1,40 @@
+{
+ "STAGE DEPENDENCIES": { "Stage-0": { "ROOT STAGE": "TRUE" } },
+ "STAGE PLANS": {
+ "Stage-0": {
+ "Fetch Operator": {
+ "limit:": "-1",
+ "Processor Tree:": {
+ "TableScan": {
+ "alias:": "customers",
+ "columns:": ["id", "name", "city"],
+ "database:": "default",
+ "filterExpr:": "(city = 'berlin') (type: boolean)",
+ "table:": "customers",
+ "isTempTable:": "false",
+ "OperatorId:": "TS_0",
+ "children": {
+ "Filter Operator": {
+ "predicate:": "(city = 'berlin') (type: boolean)",
+ "OperatorId:": "FIL_4",
+ "children": {
+ "Select Operator": {
+ "expressions:": "id (type: int), name (type: string), 'berlin' (type: string)",
+ "columnExprMap:": {
+ "_col0": "id",
+ "_col1": "name",
+ "_col2": "'berlin'"
+ },
+ "outputColumnNames:": ["_col0", "_col1", "_col2"],
+ "OperatorId:": "SEL_2",
+ "children": { "ListSink": { "OperatorId:": "LIST_SINK_5" } }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/frontend/src/apps/explain-visualizer/test-data/hive/order-limit.json b/frontend/src/apps/explain-visualizer/test-data/hive/order-limit.json
new file mode 100644
index 0000000000..e507ddf766
--- /dev/null
+++ b/frontend/src/apps/explain-visualizer/test-data/hive/order-limit.json
@@ -0,0 +1,106 @@
+{
+ "CBOPlan": "{\n \"rels\": [\n {\n \"id\": \"0\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableScan\",\n \"table\": [\n \"default\",\n \"customers\"\n ],\n \"table:alias\": \"customers\",\n \"inputs\": [],\n \"rowCount\": 1.0,\n \"avgRowSize\": 100.0,\n \"rowType\": [\n {\n \"type\": \"INTEGER\",\n \"nullable\": true,\n \"name\": \"id\"\n },\n {\n \"type\": \"VARCHAR\",\n \"nullable\": true,\n \"precision\": 2147483647,\n \"name\": \"name\"\n },\n {\n \"type\": \"VARCHAR\",\n \"nullable\": true,\n \"precision\": 2147483647,\n \"name\": \"city\"\n },\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"BLOCK__OFFSET__INSIDE__FILE\"\n },\n {\n \"type\": \"VARCHAR\",\n \"nullable\": true,\n \"precision\": 2147483647,\n \"name\": \"INPUT__FILE__NAME\"\n },\n {\n \"fields\": [\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"writeid\"\n },\n {\n \"type\": \"INTEGER\",\n \"nullable\": true,\n \"name\": \"bucketid\"\n },\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"rowid\"\n }\n ],\n \"name\": \"ROW__ID\"\n },\n {\n \"type\": \"BOOLEAN\",\n \"nullable\": true,\n \"name\": \"ROW__IS__DELETED\"\n }\n ],\n \"colStats\": [\n {\n \"name\": \"city\",\n \"ndv\": 1\n },\n {\n \"name\": \"id\",\n \"ndv\": 1,\n \"minValue\": -9223372036854775808,\n \"maxValue\": 9223372036854775807\n },\n {\n \"name\": \"name\",\n \"ndv\": 1\n }\n ]\n },\n {\n \"id\": \"1\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject\",\n \"fields\": [\n \"city\"\n ],\n \"exprs\": [\n {\n \"input\": 2,\n \"name\": \"$2\"\n }\n ],\n \"rowCount\": 1.0\n },\n {\n \"id\": \"2\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveSortLimit\",\n \"collation\": [\n {\n \"field\": 0,\n \"direction\": \"ASCENDING\",\n \"nulls\": \"LAST\"\n }\n ],\n \"fetch\": {\n \"literal\": 5,\n \"type\": {\n \"type\": \"INTEGER\",\n \"nullable\": false\n }\n },\n \"rowCount\": 1.0\n }\n ]\n}",
+ "optimizedSQL": "SELECT `city`\nFROM `default`.`customers`\nORDER BY `city`\nLIMIT 5",
+ "cboInfo": "Plan optimized by CBO.",
+ "STAGE DEPENDENCIES": {
+ "Stage-1": { "ROOT STAGE": "TRUE" },
+ "Stage-0": { "DEPENDENT STAGES": "Stage-1" }
+ },
+ "STAGE PLANS": {
+ "Stage-1": {
+ "Tez": {
+ "DagId:": "hive_20261027075648_2efae7b9-2707-4e26-8aae-3db15b14fde2:5",
+ "Edges:": { "Reducer 2": { "parent": "Map 1", "type": "SIMPLE_EDGE" } },
+ "DagName:": "hive_20261027075648_2efae7b9-2707-4e26-8aae-3db15b14fde2:5",
+ "Vertices:": {
+ "Map 1": {
+ "Map Operator Tree:": [
+ {
+ "TableScan": {
+ "alias:": "customers",
+ "columns:": ["city"],
+ "database:": "default",
+ "Statistics:": "Num rows: 1 Data size: 184 Basic stats: COMPLETE Column stats: NONE",
+ "table:": "customers",
+ "isTempTable:": "false",
+ "OperatorId:": "TS_0",
+ "children": {
+ "Top N Key Operator": {
+ "sort order:": "+",
+ "keys:": "city (type: string)",
+ "null sort order:": "z",
+ "Statistics:": "Num rows: 1 Data size: 184 Basic stats: COMPLETE Column stats: NONE",
+ "top n:": "5",
+ "OperatorId:": "TNK_7",
+ "children": {
+ "Select Operator": {
+ "expressions:": "city (type: string)",
+ "columnExprMap:": { "_col0": "city" },
+ "outputColumnNames:": ["_col0"],
+ "Statistics:": "Num rows: 1 Data size: 184 Basic stats: COMPLETE Column stats: NONE",
+ "OperatorId:": "SEL_8",
+ "children": {
+ "Reduce Output Operator": {
+ "columnExprMap:": {
+ "KEY.reducesinkkey0": "_col0"
+ },
+ "key expressions:": "_col0 (type: string)",
+ "null sort order:": "z",
+ "sort order:": "+",
+ "Statistics:": "Num rows: 1 Data size: 184 Basic stats: COMPLETE Column stats: NONE",
+ "OperatorId:": "RS_9",
+ "outputname:": "Reducer 2",
+ "outputOperator:": ["SEL_10"]
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ ],
+ "Execution mode:": "vectorized"
+ },
+ "Reducer 2": {
+ "Execution mode:": "vectorized",
+ "Reduce Operator Tree:": {
+ "Select Operator": {
+ "expressions:": "KEY.reducesinkkey0 (type: string)",
+ "columnExprMap:": { "_col0": "KEY.reducesinkkey0" },
+ "outputColumnNames:": ["_col0"],
+ "Statistics:": "Num rows: 1 Data size: 184 Basic stats: COMPLETE Column stats: NONE",
+ "OperatorId:": "SEL_10",
+ "children": {
+ "Limit": {
+ "Number of rows:": "5",
+ "Statistics:": "Num rows: 1 Data size: 184 Basic stats: COMPLETE Column stats: NONE",
+ "OperatorId:": "LIM_11",
+ "children": {
+ "File Output Operator": {
+ "compressed:": "false",
+ "Statistics:": "Num rows: 1 Data size: 184 Basic stats: COMPLETE Column stats: NONE",
+ "table:": {
+ "input format:": "org.apache.hadoop.mapred.SequenceFileInputFormat",
+ "output format:": "org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat",
+ "serde:": "org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe"
+ },
+ "OperatorId:": "FS_12"
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "Stage-0": {
+ "Fetch Operator": {
+ "limit:": "5",
+ "Processor Tree:": { "ListSink": { "OperatorId:": "LIST_SINK_13" } }
+ }
+ }
+ }
+}
diff --git a/frontend/src/apps/explain-visualizer/test-data/hive/single-scan.json b/frontend/src/apps/explain-visualizer/test-data/hive/single-scan.json
new file mode 100644
index 0000000000..4431f7bd2f
--- /dev/null
+++ b/frontend/src/apps/explain-visualizer/test-data/hive/single-scan.json
@@ -0,0 +1,43 @@
+{
+ "CBOPlan": "{\n \"rels\": [\n {\n \"id\": \"0\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableScan\",\n \"table\": [\n \"default\",\n \"customers\"\n ],\n \"table:alias\": \"customers\",\n \"inputs\": [],\n \"rowCount\": 1.0,\n \"avgRowSize\": 204.0,\n \"rowType\": [\n {\n \"type\": \"INTEGER\",\n \"nullable\": true,\n \"name\": \"id\"\n },\n {\n \"type\": \"VARCHAR\",\n \"nullable\": true,\n \"precision\": 2147483647,\n \"name\": \"name\"\n },\n {\n \"type\": \"VARCHAR\",\n \"nullable\": true,\n \"precision\": 2147483647,\n \"name\": \"city\"\n },\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"BLOCK__OFFSET__INSIDE__FILE\"\n },\n {\n \"type\": \"VARCHAR\",\n \"nullable\": true,\n \"precision\": 2147483647,\n \"name\": \"INPUT__FILE__NAME\"\n },\n {\n \"fields\": [\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"writeid\"\n },\n {\n \"type\": \"INTEGER\",\n \"nullable\": true,\n \"name\": \"bucketid\"\n },\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"rowid\"\n }\n ],\n \"name\": \"ROW__ID\"\n },\n {\n \"type\": \"BOOLEAN\",\n \"nullable\": true,\n \"name\": \"ROW__IS__DELETED\"\n }\n ],\n \"colStats\": [\n {\n \"name\": \"id\",\n \"ndv\": 1,\n \"minValue\": -9223372036854775808,\n \"maxValue\": 9223372036854775807\n },\n {\n \"name\": \"name\",\n \"ndv\": 1\n },\n {\n \"name\": \"city\",\n \"ndv\": 1\n }\n ]\n },\n {\n \"id\": \"1\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveFilter\",\n \"condition\": {\n \"op\": {\n \"name\": \"=\",\n \"kind\": \"EQUALS\",\n \"syntax\": \"BINARY\"\n },\n \"operands\": [\n {\n \"input\": 2,\n \"name\": \"$2\"\n },\n {\n \"literal\": \"berlin\",\n \"type\": {\n \"type\": \"VARCHAR\",\n \"nullable\": false,\n \"precision\": 2147483647\n }\n }\n ]\n },\n \"rowCount\": 1.0\n },\n {\n \"id\": \"2\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject\",\n \"fields\": [\n \"id\",\n \"name\",\n \"city\"\n ],\n \"exprs\": [\n {\n \"input\": 0,\n \"name\": \"$0\"\n },\n {\n \"input\": 1,\n \"name\": \"$1\"\n },\n {\n \"op\": {\n \"name\": \"CAST\",\n \"kind\": \"CAST\",\n \"syntax\": \"SPECIAL\"\n },\n \"operands\": [\n {\n \"literal\": \"berlin\",\n \"type\": {\n \"type\": \"VARCHAR\",\n \"nullable\": false,\n \"precision\": 2147483647\n }\n }\n ],\n \"type\": {\n \"type\": \"VARCHAR\",\n \"nullable\": true,\n \"precision\": 2147483647\n }\n }\n ],\n \"rowCount\": 1.0\n }\n ]\n}",
+ "optimizedSQL": "SELECT `id`, `name`, CAST('berlin' AS STRING) AS `city`\nFROM `default`.`customers`\nWHERE `city` = 'berlin'",
+ "cboInfo": "Plan optimized by CBO.",
+ "STAGE DEPENDENCIES": { "Stage-0": { "ROOT STAGE": "TRUE" } },
+ "STAGE PLANS": {
+ "Stage-0": {
+ "Fetch Operator": {
+ "limit:": "-1",
+ "Processor Tree:": {
+ "TableScan": {
+ "alias:": "customers",
+ "columns:": ["id", "name", "city"],
+ "database:": "default",
+ "filterExpr:": "(city = 'berlin') (type: boolean)",
+ "table:": "customers",
+ "isTempTable:": "false",
+ "OperatorId:": "TS_0",
+ "children": {
+ "Filter Operator": {
+ "predicate:": "(city = 'berlin') (type: boolean)",
+ "OperatorId:": "FIL_4",
+ "children": {
+ "Select Operator": {
+ "expressions:": "id (type: int), name (type: string), 'berlin' (type: string)",
+ "columnExprMap:": {
+ "_col0": "id",
+ "_col1": "name",
+ "_col2": "'berlin'"
+ },
+ "outputColumnNames:": ["_col0", "_col1", "_col2"],
+ "OperatorId:": "SEL_2",
+ "children": { "ListSink": { "OperatorId:": "LIST_SINK_5" } }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/frontend/src/apps/explain-visualizer/test-data/hive/union-all.json b/frontend/src/apps/explain-visualizer/test-data/hive/union-all.json
new file mode 100644
index 0000000000..6622022fdd
--- /dev/null
+++ b/frontend/src/apps/explain-visualizer/test-data/hive/union-all.json
@@ -0,0 +1,104 @@
+{
+ "CBOPlan": "{\n \"rels\": [\n {\n \"id\": \"0\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableScan\",\n \"table\": [\n \"default\",\n \"customers\"\n ],\n \"table:alias\": \"customers\",\n \"inputs\": [],\n \"rowCount\": 1.0,\n \"avgRowSize\": 100.0,\n \"rowType\": [\n {\n \"type\": \"INTEGER\",\n \"nullable\": true,\n \"name\": \"id\"\n },\n {\n \"type\": \"VARCHAR\",\n \"nullable\": true,\n \"precision\": 2147483647,\n \"name\": \"name\"\n },\n {\n \"type\": \"VARCHAR\",\n \"nullable\": true,\n \"precision\": 2147483647,\n \"name\": \"city\"\n },\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"BLOCK__OFFSET__INSIDE__FILE\"\n },\n {\n \"type\": \"VARCHAR\",\n \"nullable\": true,\n \"precision\": 2147483647,\n \"name\": \"INPUT__FILE__NAME\"\n },\n {\n \"fields\": [\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"writeid\"\n },\n {\n \"type\": \"INTEGER\",\n \"nullable\": true,\n \"name\": \"bucketid\"\n },\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"rowid\"\n }\n ],\n \"name\": \"ROW__ID\"\n },\n {\n \"type\": \"BOOLEAN\",\n \"nullable\": true,\n \"name\": \"ROW__IS__DELETED\"\n }\n ],\n \"colStats\": [\n {\n \"name\": \"name\",\n \"ndv\": 1\n },\n {\n \"name\": \"city\",\n \"ndv\": 1\n },\n {\n \"name\": \"id\",\n \"ndv\": 1,\n \"minValue\": -9223372036854775808,\n \"maxValue\": 9223372036854775807\n }\n ]\n },\n {\n \"id\": \"1\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject\",\n \"fields\": [\n \"city\"\n ],\n \"exprs\": [\n {\n \"input\": 2,\n \"name\": \"$2\"\n }\n ],\n \"rowCount\": 1.0\n },\n {\n \"id\": \"2\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveTableScan\",\n \"table\": [\n \"default\",\n \"customers\"\n ],\n \"table:alias\": \"customers\",\n \"inputs\": [],\n \"rowCount\": 1.0,\n \"avgRowSize\": 100.0,\n \"rowType\": [\n {\n \"type\": \"INTEGER\",\n \"nullable\": true,\n \"name\": \"id\"\n },\n {\n \"type\": \"VARCHAR\",\n \"nullable\": true,\n \"precision\": 2147483647,\n \"name\": \"name\"\n },\n {\n \"type\": \"VARCHAR\",\n \"nullable\": true,\n \"precision\": 2147483647,\n \"name\": \"city\"\n },\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"BLOCK__OFFSET__INSIDE__FILE\"\n },\n {\n \"type\": \"VARCHAR\",\n \"nullable\": true,\n \"precision\": 2147483647,\n \"name\": \"INPUT__FILE__NAME\"\n },\n {\n \"fields\": [\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"writeid\"\n },\n {\n \"type\": \"INTEGER\",\n \"nullable\": true,\n \"name\": \"bucketid\"\n },\n {\n \"type\": \"BIGINT\",\n \"nullable\": true,\n \"name\": \"rowid\"\n }\n ],\n \"name\": \"ROW__ID\"\n },\n {\n \"type\": \"BOOLEAN\",\n \"nullable\": true,\n \"name\": \"ROW__IS__DELETED\"\n }\n ],\n \"colStats\": [\n {\n \"name\": \"id\",\n \"ndv\": 1,\n \"minValue\": -9223372036854775808,\n \"maxValue\": 9223372036854775807\n },\n {\n \"name\": \"name\",\n \"ndv\": 1\n },\n {\n \"name\": \"city\",\n \"ndv\": 1\n }\n ]\n },\n {\n \"id\": \"3\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveProject\",\n \"fields\": [\n \"name\"\n ],\n \"exprs\": [\n {\n \"input\": 1,\n \"name\": \"$1\"\n }\n ],\n \"rowCount\": 1.0\n },\n {\n \"id\": \"4\",\n \"relOp\": \"org.apache.hadoop.hive.ql.optimizer.calcite.reloperators.HiveUnion\",\n \"all\": true,\n \"inputs\": [\n \"1\",\n \"3\"\n ],\n \"rowCount\": 2.0\n }\n ]\n}",
+ "optimizedSQL": "SELECT `city`\nFROM `default`.`customers`\nUNION ALL\nSELECT `name`\nFROM `default`.`customers`",
+ "cboInfo": "Plan optimized by CBO.",
+ "STAGE DEPENDENCIES": {
+ "Stage-1": { "ROOT STAGE": "TRUE" },
+ "Stage-0": { "DEPENDENT STAGES": "Stage-1" }
+ },
+ "STAGE PLANS": {
+ "Stage-1": {
+ "Tez": {
+ "DagId:": "hive_20261027075646_79b9eb03-6563-40f0-b816-aa2a9bedb0b7:4",
+ "Edges:": {
+ "Map 1": { "parent": "Union 2", "type": "CONTAINS" },
+ "Map 3": { "parent": "Union 2", "type": "CONTAINS" }
+ },
+ "DagName:": "hive_20261027075646_79b9eb03-6563-40f0-b816-aa2a9bedb0b7:4",
+ "Vertices:": {
+ "Map 1": {
+ "Map Operator Tree:": [
+ {
+ "TableScan": {
+ "alias:": "customers",
+ "columns:": ["city"],
+ "database:": "default",
+ "Statistics:": "Num rows: 1 Data size: 184 Basic stats: COMPLETE Column stats: NONE",
+ "table:": "customers",
+ "isTempTable:": "false",
+ "OperatorId:": "TS_7",
+ "children": {
+ "Select Operator": {
+ "expressions:": "city (type: string)",
+ "columnExprMap:": { "_col0": "city" },
+ "outputColumnNames:": ["_col0"],
+ "Statistics:": "Num rows: 1 Data size: 184 Basic stats: COMPLETE Column stats: NONE",
+ "OperatorId:": "SEL_15",
+ "children": {
+ "File Output Operator": {
+ "compressed:": "false",
+ "Statistics:": "Num rows: 2 Data size: 368 Basic stats: COMPLETE Column stats: NONE",
+ "table:": {
+ "input format:": "org.apache.hadoop.mapred.SequenceFileInputFormat",
+ "output format:": "org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat",
+ "serde:": "org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe"
+ },
+ "OperatorId:": "FS_16"
+ }
+ }
+ }
+ }
+ }
+ }
+ ],
+ "Execution mode:": "vectorized"
+ },
+ "Map 3": {
+ "Map Operator Tree:": [
+ {
+ "TableScan": {
+ "alias:": "customers",
+ "columns:": ["name"],
+ "database:": "default",
+ "Statistics:": "Num rows: 1 Data size: 184 Basic stats: COMPLETE Column stats: NONE",
+ "table:": "customers",
+ "isTempTable:": "false",
+ "OperatorId:": "TS_11",
+ "children": {
+ "Select Operator": {
+ "expressions:": "name (type: string)",
+ "columnExprMap:": { "_col0": "name" },
+ "outputColumnNames:": ["_col0"],
+ "Statistics:": "Num rows: 1 Data size: 184 Basic stats: COMPLETE Column stats: NONE",
+ "OperatorId:": "SEL_17",
+ "children": {
+ "File Output Operator": {
+ "compressed:": "false",
+ "Statistics:": "Num rows: 2 Data size: 368 Basic stats: COMPLETE Column stats: NONE",
+ "table:": {
+ "input format:": "org.apache.hadoop.mapred.SequenceFileInputFormat",
+ "output format:": "org.apache.hadoop.hive.ql.io.HiveSequenceFileOutputFormat",
+ "serde:": "org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe"
+ },
+ "OperatorId:": "FS_18"
+ }
+ }
+ }
+ }
+ }
+ }
+ ],
+ "Execution mode:": "vectorized"
+ },
+ "Union 2": { "Vertex:": "Union 2" }
+ }
+ }
+ },
+ "Stage-0": {
+ "Fetch Operator": {
+ "limit:": "-1",
+ "Processor Tree:": { "ListSink": { "OperatorId:": "LIST_SINK_19" } }
+ }
+ }
+ }
+}
diff --git a/frontend/src/apps/explain-visualizer/test-data/snowflake/inner-join.json b/frontend/src/apps/explain-visualizer/test-data/snowflake/inner-join.json
new file mode 100644
index 0000000000..c9a5fd9435
--- /dev/null
+++ b/frontend/src/apps/explain-visualizer/test-data/snowflake/inner-join.json
@@ -0,0 +1,48 @@
+{
+ "GlobalStats": {
+ "partitionsTotal": 2,
+ "partitionsAssigned": 2,
+ "bytesAssigned": 1024
+ },
+ "Operations": [
+ [
+ {
+ "id": 0,
+ "operation": "Result",
+ "expressions": ["Z1.ID", "Z2.ID"]
+ },
+ {
+ "id": 1,
+ "parentOperators": [0],
+ "operation": "InnerJoin",
+ "expressions": ["joinKey: (Z2.ID = Z1.ID)"]
+ },
+ {
+ "id": 2,
+ "parentOperators": [1],
+ "operation": "TableScan",
+ "objects": ["TESTDB.TEMPORARY_DOC_TEST.Z2"],
+ "expressions": ["ID"],
+ "partitionsAssigned": 1,
+ "partitionsTotal": 1,
+ "bytesAssigned": 512
+ },
+ {
+ "id": 3,
+ "parentOperators": [1],
+ "operation": "JoinFilter",
+ "expressions": ["joinKey: (Z2.ID = Z1.ID)"]
+ },
+ {
+ "id": 4,
+ "parentOperators": [3],
+ "operation": "TableScan",
+ "objects": ["TESTDB.TEMPORARY_DOC_TEST.Z1"],
+ "expressions": ["ID"],
+ "partitionsAssigned": 1,
+ "partitionsTotal": 1,
+ "bytesAssigned": 512
+ }
+ ]
+ ]
+}
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index d122543002..f9bf7b6d7c 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -3527,6 +3527,9 @@
"cockroachdb-empty": "CockroachDB returned no query plan for this statement.",
"cockroachdb-invalid": "The query plan is not valid JSON. The diagram EXPLAIN (DISTSQL) encodes is expected.",
"cockroachdb-no-plan": "The query plan JSON contains no \"processors\" to draw.",
+ "hive-empty": "Hive returned no query plan for this statement.",
+ "hive-invalid": "The query plan is not valid JSON. Hive's EXPLAIN FORMATTED output is expected.",
+ "hive-no-plan": "The query plan has no CBO plan to draw. Hive states one only when its cost-based optimizer planned the statement.",
"mongodb-empty": "MongoDB returned no query plan for this statement.",
"mongodb-invalid": "The query plan is not valid JSON. MongoDB's explain() output is expected.",
"mongodb-no-plan": "The query plan JSON has neither a \"queryPlanner\" nor a \"stages\" pipeline to draw.",
@@ -3547,6 +3550,9 @@
"postgres-no-plan": "The query plan JSON does not contain a \"Plan\" object.",
"redshift-empty": "Redshift returned no query plan for this statement.",
"redshift-no-plan": "The query plan has no operator in it: a Redshift plan states a cost for every one.",
+ "snowflake-empty": "Snowflake returned no query plan for this statement.",
+ "snowflake-invalid": "The query plan is not valid JSON. Snowflake's EXPLAIN USING JSON output is expected.",
+ "snowflake-no-plan": "The query plan JSON contains no operation to start from.",
"spanner-empty": "Spanner returned no query plan for this statement.",
"spanner-emulator": "Spanner returned no query plan for this statement. The Spanner emulator returns none for any statement, so explain it on a Spanner instance to see one.",
"spanner-invalid": "The query plan is not valid JSON. A Spanner query plan is expected.",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index d1e27f2929..09edfb0230 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -3527,6 +3527,9 @@
"cockroachdb-empty": "CockroachDB no devolvió ningún plan de consulta para esta sentencia.",
"cockroachdb-invalid": "El plan de consulta no es JSON válido. Se espera el diagrama que codifica EXPLAIN (DISTSQL).",
"cockroachdb-no-plan": "El JSON del plan de consulta no contiene \"processors\" que dibujar.",
+ "hive-empty": "Hive no devolvió ningún plan de consulta para esta sentencia.",
+ "hive-invalid": "El plan de consulta no es JSON válido. Se espera la salida de EXPLAIN FORMATTED de Hive.",
+ "hive-no-plan": "El plan de consulta no tiene un plan de CBO que dibujar. Hive solo lo indica cuando su optimizador basado en costes planificó la sentencia.",
"mongodb-empty": "MongoDB no devolvió ningún plan de consulta para esta sentencia.",
"mongodb-invalid": "El plan de consulta no es JSON válido. Se espera la salida de explain() de MongoDB.",
"mongodb-no-plan": "El JSON del plan de consulta no tiene ni \"queryPlanner\" ni una tubería \"stages\" que dibujar.",
@@ -3547,6 +3550,9 @@
"postgres-no-plan": "El JSON del plan de consulta no contiene un objeto \"Plan\".",
"redshift-empty": "Redshift no devolvió ningún plan de consulta para esta sentencia.",
"redshift-no-plan": "El plan de consulta no contiene ningún operador: un plan de Redshift indica un coste para cada uno.",
+ "snowflake-empty": "Snowflake no devolvió ningún plan de consulta para esta sentencia.",
+ "snowflake-invalid": "El plan de consulta no es JSON válido. Se espera la salida de EXPLAIN USING JSON de Snowflake.",
+ "snowflake-no-plan": "El JSON del plan de consulta no contiene ninguna operación por la que empezar.",
"spanner-empty": "Spanner no devolvió ningún plan de consulta para esta sentencia.",
"spanner-emulator": "Spanner no devolvió ningún plan de consulta para esta sentencia. El emulador de Spanner no devuelve ninguno para ninguna sentencia; explíquela en una instancia de Spanner para ver uno.",
"spanner-invalid": "El plan de consulta no es JSON válido. Se espera un plan de consulta de Spanner.",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 840179d2c0..762f5fbb7a 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -3527,6 +3527,9 @@
"cockroachdb-empty": "CockroachDB はこのステートメントのクエリプランを返しませんでした。",
"cockroachdb-invalid": "クエリプランが有効な JSON ではありません。EXPLAIN (DISTSQL) が埋め込む図が必要です。",
"cockroachdb-no-plan": "クエリプラン JSON に描画できる \"processors\" がありません。",
+ "hive-empty": "Hive はこのステートメントのクエリプランを返しませんでした。",
+ "hive-invalid": "クエリプランが有効な JSON ではありません。Hive の EXPLAIN FORMATTED の出力が必要です。",
+ "hive-no-plan": "クエリプランに描画できる CBO プランがありません。Hive はコストベースオプティマイザーがステートメントをプランした場合にのみ出力します。",
"mongodb-empty": "MongoDB はこのステートメントのクエリプランを返しませんでした。",
"mongodb-invalid": "クエリプランが有効な JSON ではありません。MongoDB の explain() の出力が必要です。",
"mongodb-no-plan": "クエリプラン JSON に \"queryPlanner\" も、描画できる \"stages\" パイプラインもありません。",
@@ -3547,6 +3550,9 @@
"postgres-no-plan": "クエリプラン JSON に \"Plan\" オブジェクトがありません。",
"redshift-empty": "Redshift はこのステートメントのクエリプランを返しませんでした。",
"redshift-no-plan": "クエリプランにオペレーターがありません。Redshift のプランは各オペレーターにコストを示します。",
+ "snowflake-empty": "Snowflake はこのステートメントのクエリプランを返しませんでした。",
+ "snowflake-invalid": "クエリプランが有効な JSON ではありません。Snowflake の EXPLAIN USING JSON の出力が必要です。",
+ "snowflake-no-plan": "クエリプラン JSON に開始できるオペレーションがありません。",
"spanner-empty": "Spanner はこのステートメントのクエリプランを返しませんでした。",
"spanner-emulator": "Spanner はこのステートメントのクエリプランを返しませんでした。Spanner エミュレーターはいずれのステートメントにもプランを返さないため、Spanner インスタンスで説明を実行してください。",
"spanner-invalid": "クエリプランが有効な JSON ではありません。Spanner クエリプランが必要です。",
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index cb7dcfa25c..7a0e4e948f 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -3527,6 +3527,9 @@
"cockroachdb-empty": "CockroachDB không trả về kế hoạch truy vấn cho câu lệnh này.",
"cockroachdb-invalid": "Kế hoạch truy vấn không phải JSON hợp lệ. Cần sơ đồ mà EXPLAIN (DISTSQL) mã hoá.",
"cockroachdb-no-plan": "JSON của kế hoạch truy vấn không chứa \"processors\" nào để vẽ.",
+ "hive-empty": "Hive không trả về kế hoạch truy vấn cho câu lệnh này.",
+ "hive-invalid": "Kế hoạch truy vấn không phải JSON hợp lệ. Cần đầu ra EXPLAIN FORMATTED của Hive.",
+ "hive-no-plan": "Kế hoạch truy vấn không có kế hoạch CBO nào để vẽ. Hive chỉ nêu kế hoạch này khi bộ tối ưu hóa dựa trên chi phí lập kế hoạch cho câu lệnh.",
"mongodb-empty": "MongoDB không trả về kế hoạch truy vấn cho câu lệnh này.",
"mongodb-invalid": "Kế hoạch truy vấn không phải JSON hợp lệ. Cần đầu ra explain() của MongoDB.",
"mongodb-no-plan": "JSON của kế hoạch truy vấn không có \"queryPlanner\" lẫn tuyến \"stages\" để vẽ.",
@@ -3547,6 +3550,9 @@
"postgres-no-plan": "JSON của kế hoạch truy vấn không chứa đối tượng \"Plan\".",
"redshift-empty": "Redshift không trả về kế hoạch truy vấn cho câu lệnh này.",
"redshift-no-plan": "Kế hoạch truy vấn không có toán tử nào: kế hoạch của Redshift nêu chi phí cho từng toán tử.",
+ "snowflake-empty": "Snowflake không trả về kế hoạch truy vấn cho câu lệnh này.",
+ "snowflake-invalid": "Kế hoạch truy vấn không phải JSON hợp lệ. Cần đầu ra EXPLAIN USING JSON của Snowflake.",
+ "snowflake-no-plan": "JSON của kế hoạch truy vấn không có toán tử nào để bắt đầu.",
"spanner-empty": "Spanner không trả về kế hoạch truy vấn cho câu lệnh này.",
"spanner-emulator": "Spanner không trả về kế hoạch truy vấn cho câu lệnh này. Trình giả lập Spanner không trả về kế hoạch cho bất kỳ câu lệnh nào; hãy giải thích câu lệnh trên một phiên bản Spanner để xem kế hoạch.",
"spanner-invalid": "Kế hoạch truy vấn không phải JSON hợp lệ. Cần một kế hoạch truy vấn Spanner.",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index c3ea7dfe40..560cb5c97e 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -3527,6 +3527,9 @@
"cockroachdb-empty": "CockroachDB 未返回此语句的查询计划。",
"cockroachdb-invalid": "查询计划不是有效的 JSON。需要 EXPLAIN (DISTSQL) 编码的图示。",
"cockroachdb-no-plan": "查询计划 JSON 不包含可绘制的 \"processors\"。",
+ "hive-empty": "Hive 未返回此语句的查询计划。",
+ "hive-invalid": "查询计划不是有效的 JSON。需要 Hive EXPLAIN FORMATTED 输出。",
+ "hive-no-plan": "查询计划中没有可绘制的 CBO 计划。只有基于代价的优化器为该语句生成计划时,Hive 才会输出它。",
"mongodb-empty": "MongoDB 未返回此语句的查询计划。",
"mongodb-invalid": "查询计划不是有效的 JSON。需要 MongoDB 的 explain() 输出。",
"mongodb-no-plan": "查询计划 JSON 既不包含 \"queryPlanner\",也不包含可绘制的 \"stages\" 管道。",
@@ -3547,6 +3550,9 @@
"postgres-no-plan": "查询计划 JSON 不包含 \"Plan\" 对象。",
"redshift-empty": "Redshift 未返回此语句的查询计划。",
"redshift-no-plan": "查询计划中没有操作符:Redshift 的计划会为每个操作符给出成本。",
+ "snowflake-empty": "Snowflake 未返回此语句的查询计划。",
+ "snowflake-invalid": "查询计划不是有效的 JSON。需要 Snowflake EXPLAIN USING JSON 输出。",
+ "snowflake-no-plan": "查询计划 JSON 中没有可作为起点的操作。",
"spanner-empty": "Spanner 未返回此语句的查询计划。",
"spanner-emulator": "Spanner 未返回此语句的查询计划。Spanner 模拟器不会为任何语句返回计划,请在 Spanner 实例上执行解释以查看计划。",
"spanner-invalid": "查询计划不是有效的 JSON。需要 Spanner 查询计划。",
diff --git a/frontend/src/modules/sql-editor/components/ResultView/SingleResultView.test.tsx b/frontend/src/modules/sql-editor/components/ResultView/SingleResultView.test.tsx
index 27a3be117a..a604a02210 100644
--- a/frontend/src/modules/sql-editor/components/ResultView/SingleResultView.test.tsx
+++ b/frontend/src/modules/sql-editor/components/ResultView/SingleResultView.test.tsx
@@ -1102,9 +1102,9 @@ describe("SingleResultView explain visualizer", () => {
);
test("keeps multi-column explain output in the result table", () => {
- // Snowflake has no parser, so there is no drawable plan to fetch and the
- // grid is all there is to show.
- tabularPlan(Engine.SNOWFLAKE, QueryOption_ExplainFormat.TEXT);
+ // Databricks explains in Spark's own FORMATTED text, which has no parser,
+ // so there is no drawable plan to fetch and the grid is all there is.
+ tabularPlan(Engine.DATABRICKS, QueryOption_ExplainFormat.TEXT);
expect(screen.queryByTestId("query-plan-result")).toBeNull();
expect(screen.getByTestId("result-table")).toHaveTextContent(
diff --git a/frontend/src/utils/queryPlanEngines.test.ts b/frontend/src/utils/queryPlanEngines.test.ts
index 344819630d..a47c0977f0 100644
--- a/frontend/src/utils/queryPlanEngines.test.ts
+++ b/frontend/src/utils/queryPlanEngines.test.ts
@@ -24,6 +24,8 @@ describe("isVisualizerEngine", () => {
Engine.OCEANBASE,
Engine.MONGODB,
Engine.COCKROACHDB,
+ Engine.SNOWFLAKE,
+ Engine.HIVE,
Engine.REDSHIFT,
Engine.STARROCKS,
Engine.DORIS,
@@ -31,7 +33,8 @@ describe("isVisualizerEngine", () => {
);
expect(isVisualizerEngine(Engine.POSTGRES)).toBe(true);
expect(isVisualizerEngine(Engine.MYSQL)).toBe(true);
- expect(isVisualizerEngine(Engine.SNOWFLAKE)).toBe(false);
+ expect(isVisualizerEngine(Engine.SNOWFLAKE)).toBe(true);
+ expect(isVisualizerEngine(Engine.DATABRICKS)).toBe(false);
});
test("names only engines the editor offers Explain on", () => {
@@ -75,6 +78,8 @@ describe("explainQueryOption", () => {
Engine.OCEANBASE,
Engine.MONGODB,
Engine.COCKROACHDB,
+ Engine.SNOWFLAKE,
+ Engine.HIVE,
]) {
expect(explainQueryOption(engine).explainFormat).toBe(
QueryOption_ExplainFormat.JSON
@@ -83,10 +88,11 @@ describe("explainQueryOption", () => {
});
test("leaves an engine the viewer cannot draw on its own default", () => {
- expect(explainQueryOption(Engine.SNOWFLAKE).explainFormat).toBe(
+ // Databricks explains, in Spark's own FORMATTED text, which has no reader.
+ expect(explainQueryOption(Engine.DATABRICKS).explainFormat).toBe(
QueryOption_ExplainFormat.EXPLAIN_FORMAT_UNSPECIFIED
);
- expect(explainQueryOption(Engine.HIVE).explainFormat).toBe(
+ expect(explainQueryOption(Engine.BIGQUERY).explainFormat).toBe(
QueryOption_ExplainFormat.EXPLAIN_FORMAT_UNSPECIFIED
);
});
diff --git a/frontend/src/utils/queryPlanEngines.ts b/frontend/src/utils/queryPlanEngines.ts
index 586b694bf1..2347da8fe4 100644
--- a/frontend/src/utils/queryPlanEngines.ts
+++ b/frontend/src/utils/queryPlanEngines.ts
@@ -24,6 +24,8 @@ export const VISUALIZER_EXPLAIN_FORMATS = {
[Engine.OCEANBASE]: "JSON",
[Engine.MONGODB]: "JSON",
[Engine.COCKROACHDB]: "JSON",
+ [Engine.SNOWFLAKE]: "JSON",
+ [Engine.HIVE]: "JSON",
// These three publish no plan as a document; their text plan is what there
// is.
[Engine.REDSHIFT]: "TEXT",
diff --git a/frontend/src/utils/v1/instance.ts b/frontend/src/utils/v1/instance.ts
index 847adb2dd1..cdd919f24d 100644
--- a/frontend/src/utils/v1/instance.ts
+++ b/frontend/src/utils/v1/instance.ts
@@ -240,6 +240,7 @@ export const instanceV1AllowsExplain = (
Engine.TIDB,
Engine.CLICKHOUSE,
Engine.COCKROACHDB,
+ Engine.DATABRICKS,
Engine.HIVE,
Engine.MSSQL,
Engine.ORACLE,