Hi Sandeep, try select.toSqlString(new AnsiSqlDialect(AnsiSqlDialect.DEFAULT_CONTEXT.withIdentifierQuoteString(""))).getSql().
Sandeep N <federatedqu...@gmail.com> 于2022年5月27日周五 06:03写道: > Hi Stamatis, > > Thanks for the quick response, I tried your suggestion as follows > > RelToSqlConverter converter = new RelToSqlConverter(new > > AnsiSqlDialect(AnsiSqlDialect.DEFAULT_CONTEXT.withIdentifierQuoteString(""))); > SqlSelect select = converter.visitRoot(relNode).asSelect(); > SqlWriterConfig config = SqlPrettyWriter.config(). > withCaseClausesOnNewLines(false). > withQuoteAllIdentifiers(false); > System.out.println(new SqlPrettyWriter(config).format(select)); > > and I still get this > SELECT "a" > FROM test_table > WHERE "b" = 'value'; > > It is not obvious to me as to what I am doing wrong. Is the above block of > code the only pieces that I need to put in play to get that sql generated? > > --Sandeep > > On Thu, May 26, 2022 at 2:22 PM Stamatis Zampetakis <zabe...@gmail.com> > wrote: > > > Hi Sandeep, > > > > If you want to turn off quoting (which I am not sure if it is a good > idea) > > when you go from relational algebra to SQL you have to customize the > > SqlDialect that you are using via Context#withIdentifierQuoteString [1]. > > You can find a small example as part of RelToSqlConverterTest here [2]. > > > > Best, > > Stamatis > > > > [1] > > > > > https://github.com/apache/calcite/blob/9bdfd9a178f493b235d8785afd94fd0c998e8cce/core/src/main/java/org/apache/calcite/sql/SqlDialect.java#L1408 > > [2] > > > > > https://github.com/zabetak/calcite/commit/ea18d28f4fb44113c414c393fe28fc94b3eecc29 > > > > On Thu, May 26, 2022 at 9:18 PM Sandeep N <federatedqu...@gmail.com> > > wrote: > > > > > Hi all, > > > > > > I am pretty aware that this question may have been asked before as I > have > > > found references on stackoverflow but have yet to stumble on a response > > > which lays out the path on solving this. > > > > > > Here is the problem I am facing - > > > I am using relational algebra to generate SQL on a table test_table > with > > > two columns a and b fed into the calcite Framework (see below) via a > > custom > > > catalog. Both a and b are varchar columns. > > > > > > FrameworkConfig config = Frameworks.newConfigBuilder(). > > > parserConfig(SqlParser.Config.DEFAULT). > > > defaultSchema(addSchemas(rootSchema, schemaName, > > schema)). > > > <--- this is where I plug my custom table. > > > traitDefs((List<RelTraitDef>) null). > > > operatorTable(sqlOperatorTable). > > > programs(Programs.heuristicJoinOrder(Programs.RULE_SET, > > > true, 2)).build() > > > > > > The relational algebra is then used to generate SQL to the > AnsiSqlDialect > > > and the resultant output SQL is > > > > > > SELECT "a" > > > FROM test_table > > > WHERE "b" = 'value'; > > > > > > I have the SqlWriterConfig setup as such > > > > > > SqlWriterConfig config = SqlPrettyWriter.config(). > > > withCaseClausesOnNewLines(false). > > > withQuoteAllIdentifiers(false); > > > > > > I have been trying to figure what needs to change in the sql writer but > > > after scanning stackoverflow it appears this is controlled by > > > CalciteConnectionConfig and potentially not the SqlWriter. Is this > > > accurate? and if so how do I assemble the right connection config when > I > > am > > > building the custom catalog? > > > > > > P.s: I am not parsing SQL but writing directly to the relational > algebra > > > nodes so SqlParser does not come into play here. > > > > > > Any pointers on how I can go about this is appreciated, say existing > > tests > > > or code which will help me put together a configuration which gets me > to > > > this sql > > > > > > SELECT a > > > FROM test_table > > > WHERE b = 'value'; > > > > > > Thanks in advance. > > > > > > --Sandeep > > > > > >