参考图
实际上是继承自calcite 的sql 方言类
arp 扩展的说明
目前官方的arp 主要是对于sql 数据库类型的高级支持,当然需要依赖社区版的arp 公共包dremio-ce-jdbc-plugin
- arp 扩展提供的能力
- schema 获取
- 执行sql
- 数据源创建
- sql 执行规则
- sql reader
- 基于yaml 的类型以及规则处理(TypeMapper)同时支持基于yaml 定义很强大,对于我们不太懂calcite 的人员都可以进行arp 的开发
- StoragePluginTypeRulesFactory (此方法的扩展能力很强,可以基于配置管理)
- jdbc arp 扩展模式
dremio arp 高级的地方就在,我们可以随便扩展,一般我们需要实现的是配置、sql 方言(简单的就行)以及yaml 定义
抽象类定义
public abstract class AbstractDremioSqlDialect extends DremioSqlDialect {
protected AbstractDremioSqlDialect(String databaseProductName, String identifierQuoteString, NullCollation nullCollation) {
super(databaseProductName, identifierQuoteString, nullCollation);
}
public abstract JdbcSchemaFetcher newSchemaFetcher(JdbcPluginConfig var1);
}
基本实现
public class JdbcDremioSqlDialect extends AbstractDremioSqlDialect {
public static final JdbcDremioSqlDialect DERBY;
// RelToSqlConverter
public JdbcDremioRelToSqlConverter getConverter() {
return new JdbcDremioRelToSqlConverterBase(this);
}
protected JdbcDremioSqlDialect(String databaseProductName, String identifierQuoteString, NullCollation nullCollation) {
super(databaseProductName, identifierQuoteString, nullCollation);
}
// schema 处理
public JdbcSchemaFetcher newSchemaFetcher(JdbcPluginConfig config) {
return new JdbcSchemaFetcherImpl(config);
}
// TypeMapper
public TypeMapper getDataTypeMapper(JdbcPluginConfig config) {
return AutomaticTypeMapper.INSTANCE;
}
public boolean supportsNullReturnType() {
return true;
}
static {
DERBY = new JdbcDremioSqlDialect(DatabaseProduct.DERBY.name(), "\"", NullCollation.HIGH);
}
}
ArpDialect 实现
子类
DremioRelToSqlConverter调用链
stack com.dremio.exec.store.jdbc.rel2sql.MySQLRelToSqlConverter visit
Press Q or Ctrl+C to abort.
Affect(class count: 1 , method count: 4) cost in 171 ms, listenerId: 7
ts=2022-10-19 15:15:48;thread_name=1cafeb5b-fcd9-c5b8-8228-17c2d9ebcc00/0:foreman-planning;id=176;is_daemon=true;priority=10;TCCL=sun.misc.Launcher$AppClassLoader@18b4aac2
@com.dremio.exec.store.jdbc.rel2sql.MySQLRelToSqlConverter.visit()
at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-2)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.calcite.util.ReflectUtil$2.invoke(ReflectUtil.java:524)
at com.dremio.common.rel2sql.RelToSqlConverter.dispatch(RelToSqlConverter.java:113)
at com.dremio.common.rel2sql.RelToSqlConverter.visitChild(RelToSqlConverter.java:120)
at com.dremio.exec.store.jdbc.rel.JdbcPrel.<init>(JdbcPrel.java:187)
at com.dremio.exec.store.jdbc.rel.JdbcIntermediatePrel.finalizeRel(JdbcIntermediatePrel.java:64)
at com.dremio.exec.planner.sql.handlers.PrelFinalizer.visit(PrelFinalizer.java:31)
at org.apache.calcite.rel.AbstractRelNode.accept(AbstractRelNode.java:232)
at com.dremio.exec.planner.StatelessRelShuttleImpl.visitChild(StatelessRelShuttleImpl.java:37)
at org.apache.calcite.rel.RelShuttleImpl.visitChildren(RelShuttleImpl.java:61)
at org.apache.calcite.rel.RelShuttleImpl.visit(RelShuttleImpl.java:123)
at com.dremio.exec.planner.sql.handlers.PrelFinalizer.visit(PrelFinalizer.java:33)
at org.apache.calcite.rel.AbstractRelNode.accept(AbstractRelNode.java:232)
at com.dremio.exec.planner.StatelessRelShuttleImpl.visitChild(StatelessRelShuttleImpl.java:37)
at org.apache.calcite.rel.RelShuttleImpl.visitChildren(RelShuttleImpl.java:61)
at org.apache.calcite.rel.RelShuttleImpl.visit(RelShuttleImpl.java:123)
at com.dremio.exec.planner.sql.handlers.PrelFinalizer.visit(PrelFinalizer.java:33)
at org.apache.calcite.rel.AbstractRelNode.accept(AbstractRelNode.java:232)
at com.dremio.exec.planner.StatelessRelShuttleImpl.visitChild(StatelessRelShuttleImpl.java:37)
at org.apache.calcite.rel.RelShuttleImpl.visitChildren(RelShuttleImpl.java:61)
at org.apache.calcite.rel.RelShuttleImpl.visit(RelShuttleImpl.java:123)
at com.dremio.exec.planner.sql.handlers.PrelFinalizer.visit(PrelFinalizer.java:33)
at org.apache.calcite.rel.AbstractRelNode.accept(AbstractRelNode.java:232)
at com.dremio.exec.planner.StatelessRelShuttleImpl.visitChild(StatelessRelShuttleImpl.java:37)
at org.apache.calcite.rel.RelShuttleImpl.visitChildren(RelShuttleImpl.java:61)
at org.apache.calcite.rel.RelShuttleImpl.visit(RelShuttleImpl.java:123)
at com.dremio.exec.planner.sql.handlers.PrelFinalizer.visit(PrelFinalizer.java:33)
at org.apache.calcite.rel.AbstractRelNode.accept(AbstractRelNode.java:232)
at com.dremio.exec.planner.sql.handlers.PrelTransformer.convertToPrel(PrelTransformer.java:678)
at com.dremio.exec.planner.sql.handlers.query.NormalHandler.getPlan(NormalHandler.java:83)
at com.dremio.exec.planner.sql.handlers.commands.HandlerToExec.plan(HandlerToExec.java:59)
at com.dremio.exec.work.foreman.AttemptManager.plan(AttemptManager.java:494)
at com.dremio.exec.work.foreman.AttemptManager.lambda$run$4(AttemptManager.java:392)
at com.dremio.service.commandpool.ReleasableBoundCommandPool.lambda$getWrappedCommand$3(ReleasableBoundCommandPool.java:138)
at com.dremio.service.commandpool.CommandWrapper.run(CommandWrapper.java:62)
at com.dremio.context.RequestContext.run(RequestContext.java:95)
at com.dremio.common.concurrent.ContextMigratingExecutorService.lambda$decorate$3(ContextMigratingExecutorService.java:199)
at com.dremio.common.concurrent.ContextMigratingExecutorService$ComparableRunnable.run(ContextMigratingExecutorService.java:180)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:750)
TypeMapper 提供的能力
jdbc arp 扩展插件的实现,子类如下,主要实现了类型映射处理,同时扩展了一个支持基于yaml 定义的模版比较方便,我们一般arp 类型映射也是基于此的
说明
以上是一个简单的说明,实际上DremioSqlDialect 还是比较复杂的,依赖不少东西,如果比较熟悉apache calcite 会比较方便学习
参考资料
https://www.dremio.com/resources/tutorials/how-to-create-an-arp-connector/
https://github.com/dremio-hub/dremio-sqllite-connector