apache-calcite

How to change Calcite's default sql grammar?"

女生的网名这么多〃 提交于 2021-02-06 12:56:09
问题 How to change Calcite's default sql grammar, to support such sql statement "select func(id) as (a, b, c) from xx;" 回答1: To change the grammar accepted by the SQL parser, you will need to change the parser. There are two ways of doing this. The first is to fork the project and change the core grammar, Parser.jj. But as always when you fork a project, you are responsible for re-applying your changes each time you upgrade to a new version of the project. The second is to use one of the grammar

How to push down project, filter, aggregation to TableScan in Calcite

和自甴很熟 提交于 2020-05-24 20:37:31
问题 I am using Apache Calcite to implement a distributed OLAP system, which datasource is RDBMS. So I want to push down the project/filter/aggregation in RelNode tree to MyTableScan extends TableScan . In MyTableScan , a RelBuilder to get the pushed RelNode . At last, RelBuilder to generate the Query to the source database. At the same time, the project/filter/aggregation in original RelNode tree should be moved or modified. As I known, Calcite does not support this feature. Current limitations:

Calcite: can we rewrite the optimized RelNode?

可紊 提交于 2020-03-25 19:38:05
问题 In Calcite, after optimization provided by the default VolcanoPlanner, we can get an optimized RelNode, but can we have a further optimization? For example I want to add an ElasticsearchSort or something like that to limit the dataset we handle. Someone suggests we can define a RelOptRule, but since VolcanoPlanner handles the optimization in dynamic programming way, not sure if the rule can be applied in the right order. Any ideas? 回答1: You don't have to use VolcanoPlanner. There's also

Apache Calcite to Find Selected Columns in an SQL String

拟墨画扇 提交于 2020-03-23 12:11:37
问题 I have a use case where I want to know the columns which have been selected in an SQL string.For instance, if the SQL is like this: SELECT name, age*5 as intelligence FROM bla WHERE bla=bla Then, after parsing the above String, I just want the output to be: name, intelligence . Firstly, is it possible through Calcite? Any other option is also welcome. PS: I want to know this before actually running the query on database. 回答1: This is definitely doable with Calcite. You'll want to start by

Adding a User-Defined Function to Calcite

微笑、不失礼 提交于 2020-01-24 03:15:09
问题 I need to add a user-defined function to Calcite that takes an integer as a parameter and returns an integer. public class SquareFunction { public int eval(int a) { return a*a; } } and the relevant code that creates a schema and adds the function is SchemaPlus rootSchema = Frameworks.createRootSchema(false); rootSchema.add("SQUARE_FUNC", ScalarFunctionImpl.create(SquareFunction.class,"eval"); But a simple SQL like select SQUARE_FUNC(1) from test; fails during the validation with the following

An exponentially decaying moving average over a hopping window in Flink SQL: Casting time

大兔子大兔子 提交于 2019-12-24 19:40:38
问题 Now we have SQL with fancy windowing in Flink, I'm trying to have the decaying moving average referred by "what will be possible in future Flink releases for both the Table API and SQL." from their SQL roadmap/preview 2017-03 post: table .window(Slide over 1.hour every 1.second as 'w) .groupBy('productId, 'w) .select( 'w.end, 'productId, ('unitPrice * ('rowtime - 'w.start).exp() / 1.hour).sum / (('rowtime - 'w.start).exp() / 1.hour).sum) Here is my attempt (inspired as well by the calcite

Why does Flink SQL use a cardinality estimate of 100 rows for all tables?

旧时模样 提交于 2019-12-20 03:01:27
问题 I wasn't sure why the logical plan wasn't correctly evaluated in this example. I looked more deeply in the Flink base code and I checked that when calcite evaluate/estimate the number of rows for the query in object. For some reason it returns always 100 for any table source . In Flink in fact, during the process of the program plan creation, for each transformed rule it is called the VolcanoPlanner class by the TableEnvironment.runVolcanoPlanner. The planner try to optimise and calculate

Having an equivalent to HOP_START inside an aggregation primitive in Flink

让人想犯罪 __ 提交于 2019-12-14 03:09:00
问题 I'm trying to do an exponentially decaying moving average over a hopping window in Flink SQL. I need the have access to one of the borders of the window, the HOP_START in the following: SELECT lb_index one_key, -- I have access to this one: HOP_START(proctime, INTERVAL '0.05' SECOND, INTERVAL '5' SECOND) start_time, -- Aggregation primitive: SUM( Y * EXP(TIMESTAMPDIFF( SECOND, proctime, -- This one throws: HOP_START(proctime, INTERVAL '0.05' SECOND, INTERVAL '5' SECOND) ))) FROM write

Calcite for VSAM

一个人想着一个人 提交于 2019-12-13 03:25:26
问题 I am trying to expose Mainframe files for more dynamic use from both COBOL programs and external programs in Java. My reading shows that I can configure COBOL to use a JDBC connection. This may be just configuration in the JCL but I assume it is more of a preprocess. I also found the JzOS libraries will give access to the VSAM datastores themselves from JAVA. So technically I think this is possible but could not find a single post on it. I know this is getting to be an edge case but I like

How can I create an External Catalog Table in Apache Flink

本小妞迷上赌 提交于 2019-12-13 00:56:41
问题 I tried to create and ExternalCatalog to use in Apache Flink Table. I created and added to the Flink table environment (here the official documentation). For some reason, the only external table present in the 'catalog', it is not found during the scan. What I missed in the code above? val catalogName = s"externalCatalog$fileNumber" val ec: ExternalCatalog = getExternalCatalog(catalogName, 1, tableEnv) tableEnv.registerExternalCatalog(catalogName, ec) val s1: Table = tableEnv.scan("S_EXT")