Hugh Pearse created CALCITE-6455:
------------------------------------
Summary: Query model table view name and model lattice name case
is different
Key: CALCITE-6455
URL: https://issues.apache.org/jira/browse/CALCITE-6455
Project: Calcite
Issue Type: Bug
Components: core
Affects Versions: 1.36.0
Reporter: Hugh Pearse
I have noticed an inconsistency for the following
==========[START model]==========
{
"version": "1.0",
"defaultSchema": "foodmart",
"schemas": [
{
"name": "foodmart",
"type": "custom",
"factory": "example.Factory",
"operand": {
"tables": [
{
"file": "product_class.json"
},
{
"file": "product.json"
},
{
"file": "sales_fact_1997.json"
},
{
"file": "time_by_day.json"
}
]
},
"lattices": [
{
"name": "star",
"sql": [
"select 1 from \"foodmart\".\"sales_fact_1997\" as \"s\"",
"join \"foodmart\".\"product\" as \"p\" using (\"product_id\")",
"join \"foodmart\".\"time_by_day\" as \"t\" using
(\"time_id\")",
"join \"foodmart\".\"product_class\" as \"pc\" on
\"p\".\"product_class_id\" = \"pc\".\"product_class_id\""
],
"auto": false,
"algorithm": true,
"rowCountEstimate": 86837,
"defaultMeasures": [
{
"agg": "count"
}
],
"tiles": [
{
"dimensions": [
"the_year",
[
"t",
"quarter"
]
],
"measures": [
{
"agg": "sum",
"args": "unit_sales"
},
{
"agg": "sum",
"args": "store_sales"
},
{
"agg": "count"
}
]
}
]
}
],
"tables": [
{
"name": "v_sales_fact_1997",
"type": "view",
"sql": "select product_id, customer_id from
foodmart.sales_fact_1997 where product_id=123",
"modifiable": false
}
]
}
]
}
==========[END model]==========
==========[START happy path]==========
FrameworkConfig frameworkConfig = Frameworks.newConfigBuilder()
.parserConfig(
SqlParser.config()
.withCaseSensitive(false)
.withUnquotedCasing(Casing.UNCHANGED)
.withLex(Lex.JAVA)
)
.defaultSchema(connection.getRootSchema().getSubSchema(connection.getSchema()))
.build();
Planner planner = Frameworks.getPlanner(frameworkConfig);
// THIS WORKS
// ===> String sqlInput = "select customer_id, product_name from
foodmart.star";
System.out.println("\nInput SQL is: \n"+sqlInput);
SqlNode sqlNodeInput = planner.parse(sqlInput);
SqlNode sqlNodeInputValidated = planner.validate(sqlNodeInput);
==========[END happy path]==========
==========[START unhappy path]==========
FrameworkConfig frameworkConfig = Frameworks.newConfigBuilder()
.parserConfig(
SqlParser.config()
.withCaseSensitive(false)
.withUnquotedCasing(Casing.UNCHANGED)
.withLex(Lex.JAVA)
)
.defaultSchema(connection.getRootSchema().getSubSchema(connection.getSchema()))
.build();
Planner planner = Frameworks.getPlanner(frameworkConfig);
// THIS FAILS
// ===> String sqlInput = "select customer_id, product_name from
foodmart.v_sales_fact_1997";
System.out.println("\nInput SQL is: \n"+sqlInput);
SqlNode sqlNodeInput = planner.parse(sqlInput);
SqlNode sqlNodeInputValidated = planner.validate(sqlNodeInput);
==========[END unhappy path]==========
The error is as follows:
Exception in thread "main" org.apache.calcite.tools.ValidationException:
org.apache.calcite.runtime.CalciteContextException: From line 1, column 37
to line 1, column 60: Object 'FOODMART' not found; did you mean 'foodmart'?
Why does parsing a query for a view get converted to uppercase, while parsing a
query for a lattice does not get converted to uppercase? I believe this is a
mistake as queries for both entities should be treated the same. When the
model is parsed the entity names should be normalised to a common reference
format, and when queries are parsed and applied against a data model, the query
should be normalised to the same reference format. Somehow this is not
happening, either in model parsing or query parsing.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)