基于 Apache Calcite 的高性能内存 Hive SQL 引擎
Marble is a high performance in-memory hive sql engine based on Apache Calcite.
It can help you to migrate hive sql scripts to a real-time computing system.
It also provides a convenient Table API to help you to build custom SQL engines.
You may want another similar project: direct-spark-sql
Requirements
1.build marble
cd marble
mvn clean install -DskipTests(Optional)
if you need modify the patches of Calcite, build calcite-patch project first
git clone https://github.com/51nb/calcite-patch.git
cd calcite-patch
mvn clean install -DskipTestsIn the long term,we hope to merge the patches to Calcite finally.
2.import marble project into IDE, but please don't import calcite-patch as a submodule of marble project
3.run the test TableEnvTest and HiveTableEnvTest
Maven dependency
…API Overview
TableEnv.enableSqlPlanCacheSize(200);
TableEnv tableEnv = HiveTableEnv.getTableEnv();
DataTable t1 = tableEnv.fromJavaPojoList(pojoList);
DataTable t2 = tableEnv.fromJdbcResultSet(resultSet);
DataTable t3=tableEnv.fromRowListWithSqlTypeMap(rowList,sqlTypeMap);
tableEnv.addSubSchema("test");
tableEnv.registerTable("test","t1",t1);
tableEnv.registerTable("test","t2", t2);
DataTable queryResult = tableEnv.sqlQuery("select * from test.t1 join test.t2 on t1.id=t2.id");
List> rowList=queryResult.toMapList();It's recommended to enable plan cache for the same sql query:
TableEnv.enableSqlPlanCacheSize(200);TableEnv is the main table api to execute sql queries on a dataSet.
It can be used to:
DataTableDataTable in TableEnv's catalogDataTableThe TableEnv supports Calcite's sql dialect by default,see it's sql reference.
The goal of HiveTableEnv is to support hive sql as far as possible,developers can aslo use
a TableConfig to create a new TableEnv to support other sql dialects(MysqlTableEnv,PostgreTableEnv ..etc).
Supported hive sql features
HiveTableEnv.registerHiveFunctionPackages("com.u51.data.hive.udf"); There're some benchmark tests in the benchmark module,it compares flink,spark and marble on some simple
sql queries.
It shows how marble customized calcite in the sql processing flow:
You can find more details from calcite-patch's commit history.Now Marble uses calcite 1.18.0.
The main type mapping between calcite and hive is:
| CalciteSqlType | JavaStorageType | HiveObjectInspector |
|---|---|---|
| BIGINT | Long | LongObjectInspector |
| INTEGER | Int | IntObjectInspector |
| DOUBLE | Double | DoubleObjectInspectors |
| DECIMAL | BigDecimal | HiveDecimalObjectInspector |
| VARCHAR | String | StringObjectInspector |
| DATE | Int | DateObjectInspector |
| TIMESTAMP | Long | TimestampObjectInspector |
| ARRAY | List | StandardListObjectInspector |
| ...... | ...... | ...... |
More issues see issues.
Welcome contributions. Please use the Calcite-idea-code-style.xml under the marble directory to reformat code, and ensure that the validation of maven checker-style plugin is success after source code building.
This library is distributed under terms of Apache 2 License
暂无开放 Issues,或尚未同步最近议题。