This topic describes how to create an external catalog by using SQL statements.
Privilege requirements
To create an external catalog, the current user must have the CREATE CATALOG system privilege.
GRANT CREATE CATALOG TO user_name;
For more information about OceanBase Database privileges, see Privilege types in Oracle-compatible mode.
Syntax
The SQL statement for creating an external catalog is as follows:
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'
Parameter description:
external_catalog_name: The name of the external data catalog to be created. It is case-insensitive and is converted to uppercase for storage if not enclosed in double quotes.PROPERTIES [=] (properties_type_list): Specifies the attribute options related to the external data catalog type.odps_type_list: The list of attributes for an ODPS-type external data catalog (ODPS Catalog).hms_type_list: The list of attributes for an HMS-type external data catalog (HMS Catalog).jdbc_type_list: The list of attributes for a JDBC-type external data catalog (JDBC Catalog).
For detailed parameter descriptions of the CREATE EXTERNAL CATALOG syntax, see CREATE EXTERNAL CATALOG.
Note
Unlike MySQL-compatible mode, the CREATE EXTERNAL CATALOG statement in Oracle-compatible mode does not support the IF NOT EXISTS clause.
Examples
Create an ODPS-type external catalog
When reading from or writing to a MaxCompute data source, the value is ODPS.
Use the CREATE EXTERNAL CATALOG statement to establish a connection with MaxCompute (ODPS), enabling direct queries on ODPS table data without manually creating a mapping table. Objects under this catalog are read-only.
Example:
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;
Create an HMS-type external catalog
OceanBase Database uses the HMS Catalog feature to provide unified management of Hive metadata (Metastore). Through HMS Catalog, OceanBase can directly access data in the HDFS storage paths corresponding to Hive tables, supporting efficient data lake queries and analysis.
Notice
Before creating an HMS Catalog, if HMS is expected to access file data stored at the underlying level on HDFS, you must deploy the Java SDK environment. For detailed information about configuring the JAVA SDK environment, see Deploy the OceanBase Database JAVA SDK environment.
Example:
obclient> CREATE EXTERNAL CATALOG tmp_hms_catalog PROPERTIES = (TYPE = 'HMS', URI = 'thrift://xx.xx.xx.xx:9083');
obclient> DROP CATALOG tmp_hms_catalog;
For information about table formats supported by HMS Catalog, see the Create an HMS-type external catalog section in Create a catalog under the MySQL-compatible mode.
Create a JDBC-type external catalog
Starting from V4.4.2 BP4, the Oracle-compatible mode supports JDBC-type external catalogs. Currently, only SQL Server data sources are supported.
Notice
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 about configuring the JAVA SDK environment, see Deploy the OceanBase Database JAVA SDK environment.
Example:
obclient> CREATE EXTERNAL CATALOG test_jdbc_catalog PROPERTIES = (TYPE = 'JDBC', URL = 'jdbc:sqlserver://10.10.10.1:1433');
obclient> DROP CATALOG test_jdbc_catalog;
After successful creation, you can access tables in SQL Server using the three-part naming convention of Catalog name + Schema name + Table name, for example, test_jdbc_catalog.dbo.table_name. You can also first use SET CATALOG to switch to the target Catalog, and then access it using the two-part naming convention of Schema name.Table name, for example, dbo.table_name.
The column types of external tables are determined by the column metadata (targetType) provided by devdeps-java-extensions and are mapped to data types in the 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
- Objects under a JDBC Catalog are read-only and do not support execution of modification statements such as
INSERT,UPDATE,DELETE,ALTER TABLE, andDROP TABLE. - 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.