Skip to content

Commit

Permalink
Adds support for SHOW CATALOGS, SHOW CURRENT CATALOG, and SHOW CURREN…
Browse files Browse the repository at this point in the history
…T SCHEMA
  • Loading branch information
johnedquinn committed Jul 24, 2023
1 parent f0930d9 commit 0b15c47
Show file tree
Hide file tree
Showing 14 changed files with 232 additions and 55 deletions.
5 changes: 4 additions & 1 deletion partiql-ast/src/main/pig/partiql.ion
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ may then be further optimized by selecting better implementations of each operat
// SET SCHEMA <schema name>
(set_schema schema::symbol)

// SHOW SCHEMAS
// SHOW <something>
(show_catalogs)
(show_schemas)
(show_current_catalog)
(show_current_schema)
(show_tables)
(show_values)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,15 @@ internal sealed class AbstractPipeline(open val options: PipelineOptions) {
addPlugin(plugin)
}
addCatalogEntry(
"iondb" to ionStructOf(
"redox" to ionStructOf(
field(org.partiql.spi.connector.Constants.CONFIG_KEY_CONNECTOR_NAME, ionString("ion-db")),
field("ion-db-root", ionString("/Users/johqunn/.partiql/ion"))
field("ion-db-root", ionString("/Users/johqunn/.partiql/redox"))
)
)
addCatalogEntry(
"andes" to ionStructOf(
field(org.partiql.spi.connector.Constants.CONFIG_KEY_CONNECTOR_NAME, ionString("localdb")),
field("localdb_root", ionString("/Users/johqunn/.partiql/ion"))
"other" to ionStructOf(
field(org.partiql.spi.connector.Constants.CONFIG_KEY_CONNECTOR_NAME, ionString("ion-db")),
field("ion-db-root", ionString("/Users/johqunn/.partiql/other"))
)
)
compileOptions(compileOptions)
Expand Down
4 changes: 2 additions & 2 deletions partiql-cli/src/main/kotlin/org/partiql/cli/shell/Shell.kt
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ internal class Shell(

val session = EvaluationSession.build {
user(currentUser)
catalog("iondb")
schema("hello")
// catalog("iondb")
// schema("hello")
}

fun start() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class StaticTypeInferencer(
is PartiqlAst.Statement.SetCatalog -> TODO()
is PartiqlAst.Statement.SetSchema -> TODO()
is PartiqlAst.Statement.ShowSchemas -> TODO()
is PartiqlAst.Statement.ShowCatalogs -> TODO()
is PartiqlAst.Statement.ShowCurrentCatalog -> TODO()
is PartiqlAst.Statement.ShowCurrentSchema -> TODO()
is PartiqlAst.Statement.ShowTables -> TODO()
is PartiqlAst.Statement.ShowValues -> TODO()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ internal class PartiQLCompilerDefault(
is PartiqlPhysical.Statement.SetCatalog -> TODO()
is PartiqlPhysical.Statement.SetSchema -> TODO()
is PartiqlPhysical.Statement.ShowSchemas -> TODO()
is PartiqlPhysical.Statement.ShowCatalogs -> TODO()
is PartiqlPhysical.Statement.ShowCurrentCatalog -> TODO()
is PartiqlPhysical.Statement.ShowCurrentSchema -> TODO()
is PartiqlPhysical.Statement.ShowTables -> TODO()
is PartiqlPhysical.Statement.ShowValues -> TODO()
}
Expand All @@ -88,6 +91,9 @@ internal class PartiQLCompilerDefault(
is PartiqlPhysical.Statement.SetCatalog -> TODO()
is PartiqlPhysical.Statement.SetSchema -> TODO()
is PartiqlPhysical.Statement.ShowSchemas -> TODO()
is PartiqlPhysical.Statement.ShowCatalogs -> TODO()
is PartiqlPhysical.Statement.ShowCurrentCatalog -> TODO()
is PartiqlPhysical.Statement.ShowCurrentSchema -> TODO()
is PartiqlPhysical.Statement.ShowTables -> TODO()
is PartiqlPhysical.Statement.ShowValues -> TODO()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,9 @@ internal class EvaluatingCompiler(
is PartiqlAst.Statement.SetCatalog -> compileSetCatalog(ast, ast.metas)
is PartiqlAst.Statement.SetSchema -> compileSetSchema(ast, ast.metas)
is PartiqlAst.Statement.ShowSchemas -> compileShowSchemas(ast, ast.metas)
is PartiqlAst.Statement.ShowCatalogs -> compileShowCatalogs(ast, ast.metas)
is PartiqlAst.Statement.ShowCurrentCatalog -> compileShowCurrentCatalog(ast, ast.metas)
is PartiqlAst.Statement.ShowCurrentSchema -> compileShowCurrentSchema(ast, ast.metas)
is PartiqlAst.Statement.ShowTables -> compileShowTables(ast, ast.metas)
is PartiqlAst.Statement.ShowValues -> compileShowValues(ast, ast.metas)
}
Expand All @@ -451,6 +454,28 @@ internal class EvaluatingCompiler(
}
}

private fun compileShowCatalogs(node: PartiqlAst.Statement.ShowCatalogs, metas: MetaContainer): ThunkEnv {
val schemas = metadata.listCatalogs().map { ExprValue.newString(it) }
return thunkFactory.thunkEnv(metas) { _ ->
ExprValue.newList(schemas)
}
}

private fun compileShowCurrentCatalog(node: PartiqlAst.Statement.ShowCurrentCatalog, metas: MetaContainer): ThunkEnv {
return thunkFactory.thunkEnv(metas) { env ->
val currentCatalog = env.session.currentCatalog ?: return@thunkEnv ExprValue.newString("<NO CATALOG SPECIFIED>")
ExprValue.newString(currentCatalog)
}
}

private fun compileShowCurrentSchema(node: PartiqlAst.Statement.ShowCurrentSchema, metas: MetaContainer): ThunkEnv {
return thunkFactory.thunkEnv(metas) { env ->
val currentCatalog = env.session.currentCatalog ?: return@thunkEnv ExprValue.newString("<NO CATALOG SPECIFIED>")
val schema = env.session.currentSchema ?: "<NO SCHEMA SPECIFIED>"
ExprValue.newString("$currentCatalog.$schema")
}
}

private fun compileShowSchemas(node: PartiqlAst.Statement.ShowSchemas, metas: MetaContainer): ThunkEnv {
return thunkFactory.thunkEnv(metas) { env ->
val currentCatalog = env.session.currentCatalog ?: return@thunkEnv ExprValue.newList(emptyList())
Expand Down Expand Up @@ -2988,7 +3013,7 @@ internal class EvaluatingCompiler(
org.partiql.spi.BindingName(name, org.partiql.spi.BindingCase.SENSITIVE)
)
),
nullValue()
bagValue(emptyList())
)
ExprValue.newBoolean(true)
}
Expand All @@ -3001,10 +3026,10 @@ internal class EvaluatingCompiler(
val value = compileAstExpr(node.def)
return thunkFactory.thunkEnv(metas) { env ->
val session = env.session.toConnectorSession()
val currentCatalog = env.session.currentCatalog ?: "NO_CATALOG_FOUND"
val currentCatalog = env.session.currentCatalog ?: error("Not in a catalog")
val currentSchema = env.session.currentSchema?.let {
org.partiql.spi.BindingName(it, org.partiql.spi.BindingCase.SENSITIVE)
} ?: org.partiql.spi.BindingName("NO_SCHEMA_FOUND", org.partiql.spi.BindingCase.SENSITIVE)
} ?: error("NO_SCHEMA_FOUND")
val exprValue = value.invoke(env)
metadata.createValue(
session,
Expand Down Expand Up @@ -3339,17 +3364,13 @@ internal class EvaluatingCompiler(
}
}

private fun compileDml(node: PartiqlAst.Statement.Dml): ThunkEnv =
{ _ ->
err(
"DML operations are not supported yet",
ErrorCode.EVALUATOR_FEATURE_NOT_SUPPORTED_YET,
errorContextFrom(node.metas).also {
it[Property.FEATURE_NAME] = "DML Operations"
},
internal = false
)
}
private fun compileDml(node: PartiqlAst.Statement.Dml): ThunkEnv = when (node.operations.ops.first()) {
is PartiqlAst.DmlOp.Insert -> TODO()
is PartiqlAst.DmlOp.Delete -> TODO()
is PartiqlAst.DmlOp.InsertValue -> TODO()
is PartiqlAst.DmlOp.Remove -> TODO()
is PartiqlAst.DmlOp.Set -> TODO()
}

private fun compileExec(node: PartiqlAst.Statement.Exec): ThunkEnv {
val metas = node.metas
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ internal class PhysicalPlanCompilerImpl(
is PartiqlPhysical.Statement.SetCatalog -> TODO()
is PartiqlPhysical.Statement.SetSchema -> TODO()
is PartiqlPhysical.Statement.ShowSchemas -> TODO()
is PartiqlPhysical.Statement.ShowCatalogs -> TODO()
is PartiqlPhysical.Statement.ShowCurrentCatalog -> TODO()
is PartiqlPhysical.Statement.ShowCurrentSchema -> TODO()
is PartiqlPhysical.Statement.ShowTables -> TODO()
is PartiqlPhysical.Statement.ShowValues -> TODO()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ internal class Metadata(
}
}

public fun listCatalogs(): List<String> {
return catalogMap.keys.toList()
}

public fun listSchemas(session: ConnectorSession, catalog: BindingName): List<String> {
val metadataInfo = getMetadata(session, catalog) ?: return emptyList()
return metadataInfo.metadata.listSchemas(session)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class ASTPrettyPrinter {
is PartiqlAst.Statement.SetCatalog -> TODO()
is PartiqlAst.Statement.SetSchema -> TODO()
is PartiqlAst.Statement.ShowSchemas -> TODO()
is PartiqlAst.Statement.ShowCatalogs -> TODO()
is PartiqlAst.Statement.ShowCurrentCatalog -> TODO()
is PartiqlAst.Statement.ShowCurrentSchema -> TODO()
is PartiqlAst.Statement.ShowTables -> TODO()
is PartiqlAst.Statement.ShowValues -> TODO()
}
Expand Down Expand Up @@ -89,6 +92,9 @@ class ASTPrettyPrinter {
is PartiqlAst.Statement.SetCatalog -> TODO()
is PartiqlAst.Statement.SetSchema -> TODO()
is PartiqlAst.Statement.ShowSchemas -> TODO()
is PartiqlAst.Statement.ShowCatalogs -> TODO()
is PartiqlAst.Statement.ShowCurrentCatalog -> TODO()
is PartiqlAst.Statement.ShowCurrentSchema -> TODO()
is PartiqlAst.Statement.ShowTables -> TODO()
is PartiqlAst.Statement.ShowValues -> TODO()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,21 @@ internal class PartiQLPigVisitor(val customTypes: List<CustomType> = listOf(), p
return PartiqlAst.Statement.SetSchema(schema = visitSymbolPrimitive(ctx.symbolPrimitive()).name, metas)
}

override fun visitShowCatalogs(ctx: PartiQLParser.ShowCatalogsContext): PartiqlAst.Statement.ShowCatalogs {
val metas = ctx.SHOW().getSourceMetaContainer()
return PartiqlAst.Statement.ShowCatalogs(metas)
}

override fun visitShowCurrentCatalog(ctx: PartiQLParser.ShowCurrentCatalogContext): PartiqlAst.Statement.ShowCurrentCatalog {
val metas = ctx.SHOW().getSourceMetaContainer()
return PartiqlAst.Statement.ShowCurrentCatalog(metas)
}

override fun visitShowCurrentSchema(ctx: PartiQLParser.ShowCurrentSchemaContext): PartiqlAst.Statement.ShowCurrentSchema {
val metas = ctx.SHOW().getSourceMetaContainer()
return PartiqlAst.Statement.ShowCurrentSchema(metas)
}

override fun visitShowSchemas(ctx: PartiQLParser.ShowSchemasContext): PartiqlAst.Statement.ShowSchemas {
val metas = ctx.SHOW().getSourceMetaContainer()
return PartiqlAst.Statement.ShowSchemas(metas)
Expand Down
3 changes: 3 additions & 0 deletions partiql-parser/src/main/antlr/PartiQL.g4
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ statement
| execCommand COLON_SEMI? EOF # QueryExec
| SET CATALOG symbolPrimitive # SetCatalog
| SET SCHEMA symbolPrimitive # SetSchema
| SHOW CATALOGS # ShowCatalogs
| SHOW SCHEMAS # ShowSchemas
| SHOW CURRENT CATALOG # ShowCurrentCatalog
| SHOW CURRENT SCHEMA # ShowCurrentSchema
| SHOW TABLES # ShowTables
| SHOW VALUES # ShowValues
;
Expand Down
1 change: 1 addition & 0 deletions partiql-parser/src/main/antlr/PartiQLTokens.g4
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ CASCADED: 'CASCADED';
CASE: 'CASE';
CAST: 'CAST';
CATALOG: 'CATALOG';
CATALOGS: 'CATALOGS';
CHAR: 'CHAR';
CHARACTER: 'CHARACTER';
CHARACTER_LENGTH: 'CHARACTER_LENGTH';
Expand Down
Loading

0 comments on commit 0b15c47

Please sign in to comment.