Purpose
This statement is used to create a Location object. A Location object stores the access path and authentication information for external tables and temporary external tables, enabling the database to read or write external data.
Note
For OceanBase Database V4.4.x, the CREATE LOCATION statement is supported starting from V4.4.1.
Privilege requirements
Execution privilege:
To execute the
CREATE LOCATIONstatement, the current user must have theCREATE LOCATIONprivilege. For more information about privileges in OceanBase Database, see Privilege types in Oracle mode.Credential privilege:
The provided
ACCESSIDandACCESSKEYmust have valid access permissions for the target storage service.
Syntax
CREATE [OR REPLACE] LOCATION location_name
URL = 'file_path'
[CREDENTIAL = (
ACCESSID = 'string'
ACCESSKEY = 'string'
HOST = 'string'
[S3_REGION = 'string',]
[PRINCIPAL = 'string',]
[KEYTAB = 'string',]
[KRB5CONF = 'string',]
[CONFIGS = 'string',]
[USERNAME = 'string']
)
];
Parameters
| Parameter | Description |
|---|---|
| OR REPLACE | Optional. Specifies that if a Location object with the same name already exists, the new definition will replace the existing one. |
| location_name | The name of the Location object to be created. |
| URL = 'file_path' | Specifies the external storage path. Supported storage types include: local file, HDFS, OSS, and S3. For more information, see file_path. |
| CREDENTIAL | Optional. Specifies the information required to access the path. This parameter is not needed for local paths. |
| ACCESSID | Specifies the AccessKey ID for accessing the object storage. |
| ACCESSKEY | Specifies the AccessKey secret for accessing the object storage. |
| HOST | Specifies the host address of the object storage service. |
| S3_REGION | Optional. Specifies the service region for S3 object storage. |
| PRINCIPAL | Optional. Specifies the login authentication user when the target HDFS cluster is configured with Kerberos. |
| KEYTAB | Optional. Specifies the authentication key file when the target HDFS cluster is configured with Kerberos. |
| KRB5CONF | Optional. Specifies the Kerberos environment to be used by the user when the target HDFS cluster is configured with Kerberos. |
| CONFIGS | Optional. Specifies additional Hadoop client configuration parameters in the key=value format, separated by #, when the target HDFS cluster is configured with Kerberos. For more information, see configs_option. |
| USERNAME | Optional. Specifies the unique identifier for the user when the target HDFS cluster is configured with Kerberos. |
file_path
The path for storing external table files has the following formats:
For a local path:
URL = 'file://local_file_path', wherelocal_file_pathcan be a relative or absolute path.For an HDFS path:
URL = 'hdfs://localhost:port/PATH', wherelocalhostis the HDFS address,portis the HDFS port number, andPATHis the directory path in HDFS.For an object storage (OSS/S3) path:
URL = '{oss | s3}://bucket/remote_file_path'.
Notice
The path for creating a Location object should not contain parameters.
configs_option
| Parameter | Description |
|---|---|
| dfs.data.transfer.protection=${string} | Specifies the SASL protection level for secure connections during data block read/write operations. Valid values:
|
| dfs.nameservices=${nameservice id} | Specifies the nameservice (alias) for the current HA cluster. For example, dfs.nameservices=mycluster defines the logical cluster name as mycluster. |
| dfs.ha.namenodes.${nameservice id}=${namenode1}, ${namenode2} | Specifies the list of namenode backup IDs for the HA cluster. For example, dfs.ha.namenodes.mycluster=nn1,nn2 indicates that the cluster has two NameNodes: nn1 and nn2. |
| dfs.namenode.rpc-address.${nameservice id}.${namenode1}=${namenode 1 address} | Specifies the specific namenode for namenode1 to facilitate client routing. For example, dfs.namenode.rpc-address.mycluster.nn1=test1:18020 indicates the RPC address for nn1. |
| dfs.namenode.rpc-address.${nameservice id}.${namenode2}=${namenode 2 address} | Specifies the specific namenode for namenode2 to facilitate client routing. For example, dfs.namenode.rpc-address.mycluster.nn2=test2:18020 indicates the RPC address for nn2. |
| dfs.ha.automatic-failover.enabled.${nameservice id}=true | Enables automatic failover, allowing the HA cluster to automatically obtain and respond to requests using an available namenode. |
| dfs.client.failover.proxy.provider.${nameservice id}=org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider | Specifies the logical tool class for HA cluster failover, which can be customized and uploaded to the HA cluster as needed. |
Examples
Create a Location object with the storage location set to local.
obclient> CREATE LOCATION test_location_local URL = 'file://home/admin/test_csv';Create a Location object with the storage location set to OSS.
obclient> CREATE LOCATION test_location_oss URL = 'oss://dir' CREDENTIAL = ( ACCESSID = '******', ACCESSKEY = '******', HOST = '****' );Create a Location object with the authentication mode set to user authentication.
No Kerberos is required, but you must access it as a specific HDFS user.
Note
This applies to clusters without Kerberos authentication enabled, but where specific HDFS paths require access by a specific user.
CREATE LOCATION hdfs_user URL = 'hdfs://namenode:8020/' CREDENTIAL ( USER = 'hdfs_user_name' );Create a Location object with Kerberos enabled and HDFS in single NameNode mode (non-HA).
Note
The
dfs.data.transfer.protectionparameter inCONFIGSmust be consistent with the HDFS cluster configuration.CREATE LOCATION hdfs_kerberos_single URL = 'hdfs://namenode.example.com:8020/' CREDENTIAL ( PRINCIPAL = "hdfs/xxx@xxx.COM", KEYTAB = "/data/hdfs.keytab", KRB5CONF = "/data/krb5.conf", CONFIGS = 'dfs.data.transfer.protection=integrity' );Create a Location object with Kerberos enabled and HDFS in high availability (HA) mode.
CREATE LOCATION hdfs_kerberos_ha URL = 'hdfs://${nameservice id}' CREDENTIAL ( PRINCIPAL = "hdfs/xxx@xxx.COM", KEYTAB = "/etc/ob/hdfs.keytab", KRB5CONF = "/etc/krb5.conf", CONFIGS = 'dfs.data.transfer.protection=${string}#dfs.nameservices=${nameservice id}#dfs.ha.namenodes.${nameservice id}=${namenode1}, ${namenode2}#dfs.namenode.rpc-address.${nameservice id}.${namenode1}=${namenode 1 address}#dfs.namenode.rpc-address.${nameservice id}.${namenode2}=${namenode 2 address}#dfs.ha.automatic-failover.enabled.${nameservice id}=true#dfs.client.failover.proxy.provider.${nameservice id}=org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider' );Create a Location object without Kerberos enabled, but with HDFS in high availability (HA) mode.
Note
If Kerberos is not enabled, but HDFS is in high availability (HA) mode, you do not need to set the
PRINCIPAL,KEYTAB, andKRB5CONFparameters.CREATE LOCATION hdfs_location_ha URL = 'hdfs://${nameservice id}' CREDENTIAL ( CONFIGS = 'dfs.nameservices=${nameservice id}#dfs.ha.namenodes.${nameservice id}=${namenode1}, ${namenode2}#dfs.namenode.rpc-address.${nameservice id}.${namenode1}=${namenode 1 address}#dfs.namenode.rpc-address.${nameservice id}.${namenode2}=${namenode 2 address}#dfs.ha.automatic-failover.enabled.${nameservice id}=true#dfs.client.failover.proxy.provider.${nameservice id}=org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider' );
References
- For information about viewing files in a Location object, see SHOW.
- For information about modifying a Location object, see ALTER LOCATION.
- For information about deleting files in a Location object, see REMOVE.
- For information about deleting a Location object, see DROP LOCATION.
