Purpose
This statement is used to create a Location object. A Location object stores the path and authorization information for accessing external tables and temporary external tables, which are used by 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 OceanBase Database privileges, see Privilege classification in Oracle-compatible mode.Credential privilege:
The provided
ACCESSIDandACCESSKEYmust have valid access permissions to 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 the corresponding Location object already exists, the new Location object definition will replace the existing one. |
| location_name | The name of the Location object to be created. |
| URL = 'file_path' | Specifies the path of the external storage. 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 required 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. When the target HDFS cluster is configured with Kerberos, you must specify the login authentication user. |
| KEYTAB | Optional. When the target HDFS cluster is configured with Kerberos, you must specify the authentication key file. |
| KRB5CONF | Optional. When the target HDFS cluster is configured with Kerberos, you must specify the Kerberos environment for the user. |
| CONFIGS | Optional. When the target HDFS cluster is configured with Kerberos, you must specify additional Hadoop client configuration parameters in the key=value format, separated by #. For more information, see configs_option. |
| USERNAME | Optional. When the target HDFS cluster is configured with Kerberos, you must specify a unique identifier for the user. |
file_path
The path for storing external table files has the following formats:
Local path:
URL = 'file://local_file_path', wherelocal_file_pathcan be a relative or absolute path.HDFS path:
URL = 'hdfs://localhost:port/PATH', wherelocalhostis the HDFS address,portis the HDFS port number, andPATHis the directory path in HDFS.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=integrity | Enables data transmission integrity protection (SASL). |
| dfs.nameservices=${nameservice id} | Specifies the namesevice (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 specifies 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 specifies the RPC address for nn2. |
| dfs.ha.automatic-failover.enabled.${nameservice id}=true | Enables automatic failover, allowing the HA cluster to automatically obtain an available namenode to respond to requests. |
| dfs.client.failover.proxy.provider.${nameservice id}=org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider | Specifies the logic class for switching between primary and standby nodes in the HA cluster. You can also customize and upload the logic required by the HA cluster. |
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 user authentication mode.
Kerberos is not required, but you must access it with a specific HDFS user.
Note
This applies to clusters without Kerberos authentication enabled, but where specific HDFS paths need to be accessed by specific users.
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 mode).
Note
The value of
dfs.data.transfer.protectioninCONFIGSmust be consistent with the configuration of the HDFS cluster.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' );Kerberos is not enabled, but HDFS is 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 more information about viewing files under a Location object, see SHOW.
- For more information about modifying a Location object, see ALTER LOCATION.
- For more information about deleting files under a Location object, see REMOVE.
- For more information about deleting a Location object, see DROP LOCATION.