AI Data Lake Service (Lake AI Service, LAS), as a core component of the integrated lakehouse architecture, provides unified metadata construction and enterprise-level data permission control capabilities. It supports seamless integration with multiple compute engines, including Hive and Spark, enabling users to focus on their own business and accelerate the release of data value.
LAS has been enabled, and TOS storage is prepared.
You can currently use the LAS SDK to operate databases and data tables. For detailed configuration, see the SDK page.
tip
Varname and Region are used to specify the service access point and region. Refer to Link address for the corresponding values.
public HiveMetaStoreClient createClient() { // ak sk of the access account String ak = getAk(); String sk = getSk(); HiveConf conf = new HiveConf(); // Only supported for Volcengine internal access conf.set(HiveConf.ConfVars.METASTOREURIS.varname, "thrift://lakeformation.las.cn-beijing.ivolces.com:48869"); HiveMetaStoreClient client = new HiveMetaStoreClient(conf); client.setRegion("cn-beijing"); client.setAccessKeyIdAndSecretAccessKey(ak, sk); }
Create the test_database database using the SDK.
public void createDatabase(HiveMetaStoreClient client) throws TException { Database database = new Database(); database.setName("test_database"); // By default, automatically uses the form of catalog storage location + db name database.setLocationUri("TOS://bucket/warehouse/test_db.db"); database.setDescription("test database description"); client.createDatabase(database); }
After the database is created, it will be visible in the console interface.
public void createTable(HiveMetaStoreClient client) throws TException { Table table = new Table(); table.setDbName("test_database"); table.setTableName("test_table"); StorageDescriptor sd = new StorageDescriptor(); // Optional; by default, it will be configured as db location uri + table name sd.setLocation("TOS://bucket/warehouse/test_db.db/test_table"); List<FieldSchema> columns = new ArrayList<>(); columns.add(new FieldSchema("id", "BIGINT", "主键")); columns.add(new FieldSchema("name", "STRING", "名字")); columns.add(new FieldSchema("age", "INT", "年龄")); sd.setCols(columns); table.setSd(sd); // Set partition columns; for non-partitioned tables, this can be omitted List<FieldSchema> partitionKeys = new ArrayList<>(); partitionKeys.add(new FieldSchema("ds", "STRING", "日期")); table.setPartitionKeys(partitionKeys); // Advanced table configuration Map<String, String> tableParams = new HashMap<>(); tableParams.put("comment", "test table description"); hiveMetaStoreClient.createTable(table); }
After the data table is created, it will be visible in the console interface.
public void dropDatabase(HiveMetaStoreClient client) { client.dropDatabase("test_databse"); }
public void dropTable(HiveMetaStoreClient client) { client.dropTable("test_database", "test_table"); }
For details about EMR Serveless Spark, see the Serveless Spark Product Introduction.
Before integrating EMR Serveless Spark with LAS, confirm the following information in advance:
After confirming all the above information, you can start using the EMR Serveless Spark interface.
Click Create Job, specify the development type as Spark SQL, and specify the job queue.
Run the database creation DDL in the Spark SQL interface.
CREATE DATABASE IF NOT EXISTS test_database SET location 'TOS://bucket/warehouse/test_database'
After execution is complete, you can view the details of test_database on LAS.
Run the table creation DDL in the Spark SQL interface.
use test_database; CREATE TABLE IF NOT EXISTS test_table(id BIGINT, name STRING, age INT);
Create a partitioned table
use test_database; CREATE TABLE IF NOT EXISTS test_partition_table(id BIGINT, name STRING, age INT) PARTITIONED BY (ds STRING);
After execution is complete, you can view the details of the newly created table on LAS, and you can also see that the table directory has been created under the TOS database path.
Run DML in the Spark SQL interface.
use test_database; INSERT INTO `test_table` VALUES (1, 'tom', 12);
use test_database; INSERT INTO `test_partition_table` PARTITION(ds='20240412') VALUES (1, 'tom', 12);
After data insertion is complete, for non-partitioned tables, data files have been created in the table directory; for partitioned tables, data files have been created in the partition directory. On LAS, you can see that the table information has been updated.
After data writing is complete, run DQL to view the data just written.
use test_database; SELECT id, name, age FROM test_database;
use test_database; SELECT id, name, age FROM test_database WHERE ds = '20240412';
Before creating a Spark Jar job, you need to upload the file to be executed to the TOS path.
After the job is running, you can click the job name to view job details and logs.