MySQL HeatWave User Guide
If you choose not to Create an External Table Using Lakehouse Auto Parallel Load, you can create the table manually.
This topic contains the following sections:
Prepare to create external tables by reviewing the following:
Create the external tables that will ingest the loaded data by either using SQL syntax or JSON syntax.
CREATE TABLE Statement for SQL syntax. Also review relevant examples showing how to create external tables.
CREATE TABLE Statement for JSON syntax. Also review relevant examples showing how to create external tables.
To demonstrate how to create an external table manually, the following example specifies a single file for the table by using an OCIFS URI.
The CSV file in this example is from
Bank
Marketing. To use this file, visit
Bank
Marketing and download the
bank+marketing.zip file. Unzip the file,
and then unzip the bank.zip file. Refer
to the bank.csv file.
Prepare the files to load in the proper format. See Supported File Formats.
Upload the files to load into Object Storage. See Uploading an Object Storage Object to a Bucket in Oracle Cloud Infrastructure Documentation.
Select the method to specify the files for the external table: uniform resource identifier (URI), resource principal, or PAR. To learn more about each method, see the following:
In the terminal window, create and use the database to store the table.
mysql>CREATE DATABASE bank_data;mysql>USE DATABASE bank_data;
Set up the CREATE EXTERNAL TABLE
statement and the ENGINE_ATTRIBUTE
options to specify the parameters needed to process the
external files. In versions earlier than MySQL 9.4.0,
you must use the CREATE TABLE
statement and set ENGINE to
lakehouse, and
SECONDARY_ENGINE to
rapid.
Ensure that the table has the correct data type for each
column. For this example, columns are defined according
to the data in the bank.csv file. See
the following to learn more:
As of MySQL 9.4.0, you can use SQL syntax to set options for external tables. For earlier versions, you must set options using JSON syntax. To learn more, see Lakehouse External Table JSON Syntax and Lakehouse External Table SQL Syntax.
The following example uses SQL syntax:
mysql> CREATE EXTERNAL TABLE bank_marketing(
age int,
job varchar(255),
marital varchar(255),
education varchar(255),
default1 varchar(255),
balance float,
housing varchar(255),
loan varchar(255),
contact varchar(255),
day int,
month varchar(255),
duration float,
campaign int,
pdays float,
previous float,
poutcome varchar(255),
y varchar(255)
)
FILE_FORMAT = (FORMAT csv HEADER ON)
FILES = (URI = 'oci://mybucket@mynamespace/bucket_1/bank.csv');
If you are on MySQL 9.1.2 and earlier, you need to
update dialect with the
field delimiter and record
delimiter parameters. As of MySQL 9.2.0,
MySQL HeatWave Lakehouse can automatically detect these values. See
Lakehouse
External Table Syntax to learn more.
Where:
The CREATE EXTERNAL TABLE
statement creates the table
bank_marketing and automatically
sets ENGINE to
lakehouse, and
SECONDARY_ENGINE to
rapid.
Each column for the table is defined according to
the bank.csv file.
FORMAT defines the format of the
external file: csv.
HEADER identifies a header in the
external file.
URI sets the URI link to access
the file. Replace the link in the example with your
own.
If you are on a version earlier than MySQL 9.4.0, you must use the following JSON syntax:
mysql> CREATE EXTERNAL TABLE bank_marketing(
age int,
job varchar(255),
marital varchar(255),
education varchar(255),
default1 varchar(255),
balance float,
housing varchar(255),
loan varchar(255),
contact varchar(255),
day int,
month varchar(255),
duration float,
campaign int,
pdays float,
previous float,
poutcome varchar(255),
y varchar(255)
)
ENGINE_ATTRIBUTE='{"dialect": {"format": "csv", "has_header": true},
"file": [{ "uri": "oci://mybucket@mynamespace/bucket_1/bank.csv"}]}';
When you are ready to load the external table with data
from the specified files, use the
SECONDARY_LOAD clause in an
ALTER TABLE statement.
See
Load
Structured Data Manually.
Review different ways to specify files when creating external tables manually:
Review how to Load Structured Data Manually.