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, 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 privileges in OceanBase Database, see Privilege types in MySQL-compatible 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 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 external storage path. Supported storage types include: local files, HDFS, OSS, and S3. For more information, see [file_path] below. |
| 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, this parameter specifies the login authentication user. |
| KEYTAB | Optional. When the target HDFS cluster is configured with Kerberos, this parameter specifies the authentication key file. |
| KRB5CONF | Optional. When the target HDFS cluster is configured with Kerberos, this parameter specifies the Kerberos environment to be used. |
| CONFIGS | Optional. When the target HDFS cluster is configured with Kerberos, this parameter specifies additional Hadoop client configuration parameters in the key=value format, separated by #. For more information, see configs_option below. |
| USERNAME | Optional. When the target HDFS cluster is configured with Kerberos, this parameter specifies the unique identifier for the user. |
file_path
The path for storing external table files has the following formats:
Local path format:
URL = 'file://local_file_path', wherelocal_file_pathcan be a relative or absolute path.HDFS path format:
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 format:
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 specifies 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 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 also 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.
You do not need to use Kerberos, but you must access it with a specific HDFS user.
Note
This example is applicable to a cluster that does not use Kerberos authentication, but where specific HDFS users are required to access the HDFS paths.
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 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 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 HA mode.
Note
If Kerberos is not enabled, but HDFS is in 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 in a Location object, see SHOW.
- For more information about modifying a Location object, see ALTER LOCATION.
- For more information about deleting files in a Location object, see REMOVE.
- For more information about deleting a Location object, see DROP LOCATION.