Do not replace the existing analyzer rules (#870)

<!-- The PR description should answer 2 (maybe 3) important questions:
-->

### What

This PR fixes issues in the SQL layer where the following queries would
fail:

1. `select count(*) from "Track"`
2. `select * from "Track" where id = 1`

<!-- Consider: do we need to add a changelog entry? -->

### How

These were failing because the built-in analyzer rules that rewrite
`count(*)` and type-cast expressions weren't firing.
`with_analyzer_rules` replaces the analyzer rules of a session context
with the given list. We want our analyzer rule to be fired in addition
to the built-in analyzer rules.

Tests are being worked on in a separate PR.

V3_GIT_ORIGIN_REV_ID: 42231f97b5b28d9b7eeff0c3e592cb43ff7d952f
This commit is contained in:
Vamshi Surabhi 2024-07-22 23:03:50 -07:00 committed by hasura-bot
parent dea939923d
commit a6dbc7bb1d

View File

@ -239,18 +239,18 @@ impl Context {
default_schema: default_schema_name.map(|s| Arc::new(s.clone())),
catalog: catalog.clone(),
});
let session_state =
let mut session_state =
SessionState::new_with_config_rt(session_config, Arc::new(RuntimeEnv::default()))
.with_analyzer_rules(vec![Arc::new(
super::execute::analyzer::ReplaceTableScan::new(
default_schema_name.map(|s| Arc::new(s.clone())),
catalog.clone(),
),
)])
.with_query_planner(query_planner)
.add_optimizer_rule(Arc::new(
super::execute::optimizer::NDCPushDownProjection {},
));
// add_analyzer_rule takes a mut &self instead of mut self because of which we can't chain
// the creation of session_state
session_state.add_analyzer_rule(Arc::new(super::execute::analyzer::ReplaceTableScan::new(
default_schema_name.map(|s| Arc::new(s.clone())),
catalog.clone(),
)));
let session_context = datafusion::SessionContext::new_with_state(session_state);
session_context
.register_catalog("default", catalog as Arc<dyn datafusion::CatalogProvider>);