Note
This statement is supported starting from V4.3.5 BP2. External catalogs of the JDBC type are supported starting from V4.4.2 BP4.
Purpose
This statement is used to create an external data catalog in the database for connecting to external data sources and retrieving metadata of external data. You can use it to directly query external data without performing data import or migration.
Limitations and considerations
- Currently, you can create External Catalogs of the
ODPS,HMS, andJDBCtypes. Among them, theJDBCtype is supported starting from V4.4.2 BP4, and currently only supports connecting to SQL Server data sources. - Different from MySQL-compatible mode, the
CREATE EXTERNAL CATALOGstatement in Oracle-compatible mode does not support theIF NOT EXISTSclause. If the Catalog to be created already exists, an error will be returned. - Catalog names are case-insensitive. Catalog names not enclosed in double quotes are uniformly converted to uppercase for storage. To retain case, enclose the Catalog name in double quotes.
- Before creating an HMS Catalog, if the HMS expects to access file data stored at the underlying layer on HDFS, you must deploy the Java SDK environment. For detailed information on configuring the JAVA SDK environment, see Deploy the OceanBase Database JAVA SDK environment.
- Before creating a JDBC Catalog, you must deploy the Java SDK environment, and the devdeps-java-extensions RPM package must be version 1.0.6 or later. For detailed information on configuring the JAVA SDK environment, see Deploy the OceanBase Database JAVA SDK environment.
- Objects under an External Catalog are read-only and do not support modification statements such as
INSERT,UPDATE,DELETE,ALTER TABLE, andDROP TABLE.
Privilege requirements
To execute the CREATE EXTERNAL CATALOG statement, the current user must have the CREATE CATALOG system privilege. For detailed information about OceanBase Database privileges, see Privilege types in Oracle-compatible mode.
After a user successfully creates a Catalog, they automatically obtain the USE CATALOG object privilege for that Catalog, which can be viewed through the SYS.USER_TAB_PRIVS view.
Syntax
CREATE EXTERNAL CATALOG external_catalog_name
PROPERTIES [=] (properties_type_list)
properties_type_list:
odps_type_list
| hms_type_list
| jdbc_type_list
odps_type_list:
TYPE = 'ODPS',
[ACCESSTYPE = 'accesstype_string',]
ACCESSID = 'string',
ACCESSKEY = 'string',
STSTOKEN = 'string',
ENDPOINT = 'string',
TUNNEL_ENDPOINT = 'string',
PROJECT_NAME = 'string',
[QUOTA_NAME = 'string',]
REGION = 'string'
hms_type_list:
TYPE = 'HMS',
URI = 'string'
[, KRB5CONF = 'string']
[, KEYTAB = 'string']
[, PRINCIPAL = 'string']
[, MAX_CLIENT_POOL_SIZE = 20]
[, SOCKET_TIMEOUT = 10000000]
jdbc_type_list:
TYPE = 'JDBC',
URL = 'string'
accesstype_string:
aliyun
| sts
| app
Parameters
Parameter |
Description |
|---|---|
| external_catalog_name | The name of the external data directory to be created. It is case-insensitive and is converted to uppercase for storage if not enclosed in double quotes. |
| PROPERTIES [=] (properties_type_list) | Used to specify the attributes of the external data directory type. For details, see properties_type_list. |
properties_type_list
odps_type_list: Lists the attributes of an ODPS-type external data catalog (ODPS Catalog). For details, see odps_type_list below.hms_type_list: Lists the attributes of an HMS-type external data catalog (HMS Catalog). For details, see hms_type_list below.jdbc_type_list: Lists the attributes of a JDBC-type external data catalog (JDBC Catalog). For details, see jdbc_type_list below.
odps_type_list
TYPE: Specifies the type of the external data catalog. Valid values:ODPS, which is used when reading from or writing to external tables in MaxCompute.ACCESSTYPE: Optional. Specifies the account type for accessing MaxCompute. Default value:aliyun. Account type values (case-insensitive) are as follows:aliyunstsapp
ACCESSID: Specifies the AccessKey ID. When the value ofACCESSTYPEisaliyun/appor empty, this is the AccessKey ID of analiyun/appaccount or a RAM user with MaxCompute access permissions.ACCESSKEY: Specifies the AccessKey Secret. When the value ofACCESSTYPEisaliyun/appor empty, this is the AccessKey Secret of analiyun/appaccount or a RAM user with MaxCompute access permissions.STSTOKEN: Specifies the token. When the value ofACCESSTYPEissts, this is the token for accessing the MaxCompute service.ENDPOINT: Specifies the EndPoint (domain name node) of MaxCompute.TUNNEL_ENDPOINT: Specifies the Tunnel Endpoint. The MaxCompute Catalog uses the Tunnel SDK to retrieve data.PROJECT_NAME: Specifies the project space name in MaxCompute. A project space is the basic organizational unit in MaxCompute, similar to the concept of a database or schema in traditional databases.QUOTA_NAME: Optional. Specifies the quota. In MaxCompute, a quota represents a computing resource pool (computing, access, write). If a user has configured a corresponding quota, specify the specific quota through this parameter.REGION: Specifies the region where MaxCompute is enabled.
hms_type_list
TYPE: Specifies the type of the external data directory. The valueHMSindicates that external table data is read from data managed by Hive.URI: ThethriftURI of theHMSservice to be accessed, in the formatthrift://$host:$port, where:$host: The IP address of the Thrift client.$port: thethriftport. The defaultthriftport forHMSis 9083.
KRB5CONF: Optional. The path to the Kerberos configuration file required when accessing theHMSservice with Kerberos authentication enabled.Notice
The
KRB5CONFparameter is required only when Kerberos authentication is enabled forHMS.KEYTAB: Optional. Specifies the path to theKEYTABkey file required when accessing anHMSservice with Kerberos authentication enabled. If the OceanBase cluster is deployed in a distributed manner, this file must exist on the corresponding server node for each related OBServer.Notice
The
KEYTABparameter is required only when Kerberos authentication is enabled forHMS.PRINCIPAL: Optional. Specifies the Kerberos principal name required when accessing anHMSservice with Kerberos authentication enabled. It typically follows the formatservice/HOST@REGION.com, for example,hive/hadoop@QA.COM.Notice
The
PRINCIPALparameter is required only when Kerberos authentication is enabled forHMS.MAX_CLIENT_POOL_SIZE: Optional. Specifies the maximum number of connections in the HMS client connection pool. Default value:20.SOCKET_TIMEOUT: Optional. The socket timeout period for the HMS client, in microseconds. Default value:10000000(10 seconds).
jdbc_type_list
TYPE: Specifies the type of external data directory. The value isJDBC, indicating that the external table reads data from a data source accessed through the JDBC protocol. Currently, only SQL Server data sources are supported.URL: The JDBC connection string, which is the JDBC URL for connecting to an SQL Server data source. For example:jdbc:sqlserver://10.10.10.1:1433;databaseName=master;encrypt=true;trustServerCertificate=true.
Note
URLs are stored in encrypted form. When you execute the SHOW CREATE CATALOG statement to view the catalog creation statement, the URLs are displayed masked.
The column types of external tables in a JDBC catalog are determined by the column metadata (targetType) provided by devdeps-java-extensions and are mapped to data types in Oracle-compatible mode. The main type mappings for SQL Server data sources are as follows:
SQL Server type |
Types in Oracle-compatible mode |
|---|---|
| BIT | NUMBER(1) |
| TINYINT | NUMBER(3) |
| SMALLINT | NUMBER(5) |
| INT | NUMBER(10) |
| BIGINT | NUMBER(19) |
| DECIMAL / NUMERIC | NUMBER(p,s) |
| SMALLMONEY | NUMBER(10,4) |
| MONEY | NUMBER(19,4) |
| REAL / FLOAT(24) | BINARY_FLOAT |
| FLOAT(53) / DOUBLE | BINARY_DOUBLE |
| CHAR(n) | VARCHAR2(n CHAR) |
| VARCHAR(n) | VARCHAR2(n CHAR) |
| NCHAR(n) | NVARCHAR2(n) |
| NVARCHAR(n) | NVARCHAR2(n) |
| BINARY(n) | RAW(n) |
| VARBINARY(n) | RAW(n) |
| DATE | DATE |
| TIME | INTERVAL DAY (1) TO SECOND (n) |
| SMALLDATETIME | TIMESTAMP(0) |
| DATETIME | TIMESTAMP(3) |
| DATETIME2 | TIMESTAMP(7) |
| Unsupported types | UNSUPPORTED |
Notice
If a column in an external table has a data type displayed as UNSUPPORTED, that column cannot be queried. Querying other columns is not affected.
Examples
Create a JDBC-type external catalog.
obclient> CREATE EXTERNAL CATALOG tmp_jdbc_catalog PROPERTIES = (TYPE = 'JDBC', URL = 'jdbc:sqlserver://10.10.10.1:1433'); obclient> DROP CATALOG tmp_jdbc_catalog;Create an ODPS-type external catalog and delete it when no longer in use.
obclient> CREATE EXTERNAL CATALOG tmp_odps_catalog PROPERTIES = (TYPE = 'ODPS', ACCESSID = '$odps_accessid', ACCESSKEY = '$odps_accesskey', ENDPOINT = '$odps_endpoint', TUNNEL_ENDPOINT = 'http://xxx.maxcompute.aliyun.com', PROJECT_NAME = 'odps_test_project'); obclient> DROP CATALOG tmp_odps_catalog;