SQLExecutor
概述
SQLExecutor
是 MaxCompute 为执行 SQL 提供的统一的接口,用户可以通过这一接口,提交离线作业,MCQA和MaxQA
作业,并提供了丰富的配置和方法,来满足用户多样的需求。
目录
构 建SQLExecutor实例
odps-sdk 使用SQLExecutorBuilder
类来构建SQLExecutor
实例,SQLExecutorBuilder
采用构造者模式,提供了一系列方法来对SQLExecutor
进行配置。
通过这些方法,用户可以设置执行模式、任务名称、服务名称等参数,通常每个参数都有默认值,用户可以按需使用。
构造器方法
使用SQLExecutorBuilder.builder
方法可以构建一个SQLExecutorBuilder
实例。调用build
方法可以构建SQLExecutor
实例。全部配置项参考配置选项。
public SQLExecutor build()throws OdpsException
返回值:
SQLExecutor
实例。
示例代码:
SQLExecutor executor = SQLExecutorBuilder.builder()
.odps(odps)
.taskName("my_task")
.build();
配置选项
SQLExecutorBuilder
类提供了多种配置选项,以下是各配置选项的详细说明。
设置ODPS对象(必选)
使用odps
方法可以设置ODPS对象。构建ODPS对象的方式请参考构建 ODPS 客户端。
public SQLExecutorBuilder odps(Odps odps)
参数:
odps
:Odps
对象。
设置任务名称
使用taskName
方法可以设置任务名称。对于 MCQA 作业,默认 taskName 为 console_sqlrt_task
。
对于 MaxQA 作业,默认 taskName 为 AnonymousMCQATask
。
对于离线作业,无法配置 taskName,会使用 AnonymousSQLTask
作为 taskName。
public SQLExecutorBuilder taskName(String taskName)
参数:
taskName
:任务名称。
设置Tunnel Endpoint
使用tunnelEndpoint
方法可 以设置Tunnel Endpoint。
这个接口常用于当用户网络环境受限,需要进行网络打通时,由odps endpoint自动路由的tunnel endpoint无法直接访问,需要设置指定tunnel endpoint时使用。
public SQLExecutorBuilder tunnelEndpoint(String tunnelEndpoint)
参数:
tunnelEndpoint
:Tunnel Endpoint。
设置Quota名称
使用quotaName
方法可以设置计算资源组的名称。
对于MaxQA的作业,此项为必填项,需要指定相应的交互式资源组名称,否则在创建SQLExecutor
时将抛出异常。
public SQLExecutorBuilder quotaName(String quotaName)
参数:
quotaName
:Quota名称(quota nick name)。
设置执行模式
使用executeMode
方法可以设置执行模式。
public SQLExecutorBuilder executeMode(ExecuteMode executeMode)
参数:
executeMode
:执行模式。可选项为 1.INTERACTIVE_V2
:MaxQA;2.INTERACTIVE
:MCQA;3.OFFLINE
:离线执行。
使用 MaxQA
public SQLExecutorBuilder enableMcqaV2(boolean mcqaV2)
- 参数:
mcqaV2
- 布尔值,表示是否启用 MaxQA。
启用命令API
使用enableCommandApi
方法可以启用命令API。
CommandApi
是SQLExecutor
在标准SQL语法之外,额外提供的一组命令支持。用来执行像desc table
,list table
这样的非标准SQL命令。
目前 MaxCompute SQL 也在逐步支持类似扩 展命令,因此当前版本部分扩展命令,开启这个选项后,行为会与不开启这个选项后不一致。
public SQLExecutorBuilder enableCommandApi(boolean useCommandApi)
参数:
useCommandApi
:是否启用命令API。
启用三层模型支持
使用enableOdpsNamespaceSchema
方法可 以启用ODPS命名空间三层模型(Schema)。
三层模型是 MaxCompute 推出的新模式,将原project.table
扩展为为project.schema.table
模式
public SQLExecutorBuilder enableOdpsNamespaceSchema(boolean odpsNamespaceSchema)
参数:
odpsNamespaceSchema
:是否开启三层模型支持。