Purpose
This statement is used to create a Location object. A Location object stores the paths and authentication information for accessing external tables and temporary 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 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 OR REPLACE to replace the existing Location object definition with the new one if the corresponding Location object already exists. |
| 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. 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 for 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 below. |
| 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 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 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 class for HA cluster failover, which can be customized and uploaded as needed. |
Examples
Create a Location object with a local storage path.
obclient> CREATE LOCATION test_location_local URL = 'file://home/admin/test_csv';Create a Location object with an OSS storage path.
obclient> CREATE LOCATION test_location_oss URL = 'oss://dir' CREDENTIAL = ( ACCESSID = '******', ACCESSKEY = '******', HOST = '****' );Create a Location object with a user authentication mode.
Kerberos is not required, but you must access it as a specific HDFS user.
Note
This applies to clusters that do not use Kerberos authentication, but where specific HDFS paths require a specific user to access.
CREATE LOCATION hdfs_user URL = 'hdfs://namenode:8020/' CREDENTIAL ( USER = 'hdfs_user_name' );Create a Location object with Kerberos enabled and HDFS in a single NameNode (non-HA mode).
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 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 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' );
After you create a Location object, you can use the LOAD_FILE function to read external files from the specified path into the database (as BLOBs) for document processing in OceanBase AI. For more information about the syntax, parameters, and constraints of LOAD_FILE, see LOAD_FILE.
