Foreign Table (Beta)
Foreign Table Design
Tacnode foreign tables provide a flexible and efficient way to integrate and process external data. This feature simplifies data management, enables real-time access, promotes collaboration and sharing, and optimizes storage costs. By utilizing foreign tables, Tacnode seamlessly connects to external data sources, enhancing the database's application scenarios and overall value.
Scenarios
-
Data Integration and Migration
- Link external data sources, such as files and other databases, to tables in Tacnode using foreign tables.
- Query and manipulate foreign data directly, eliminating the need to import it into Tacnode.
- Streamline the data integration and migration process, reducing the effort required for data conversion and synchronization.
-
Big Data Processing
- Connect foreign tables to large datasets on distributed file systems like HDFS.
- Use SQL queries via foreign tables to process and analyze substantial data.
- Leverage Tacnode’s query optimization and parallel processing features to enhance data processing efficiency.
-
Data Sharing and Collaboration
- Access shared foreign data sources through foreign tables across various Tacnode instances.
- Enable multiple teams or departments to collaborate and analyze data using a unified dataset.
- Simplify the data-sharing process and boost data utilization.
Supported Foreign Data Source Types
Basic Usage
Installing the Extension
Various extensions define foreign data wrappers, enabling access to diverse foreign data sources. Currently, they support file systems like Alibaba Cloud OSS, AWS S3, and other object storage through file_fdw
, Alibaba Cloud MaxCompute using odps_fdw
, AWS Glue via glue_fdw
, and Hive metadata with hive_fdw
.
Install the extension once. If it has already been installed, you can ignore it.
Creating a Foreign Server
Use the CREATE SERVER
command to establish a foreign server. This server follows the subsequent syntax:
server_name
: A designated server name.fdw_name
: The currently supported foreign data wrappers includefile_fdw
,glue_fdw
,hive_fdw
, andodps_fdw
.OPTIONS
: Theoption
may have varying parameter options depending on the foreign data wrapper.
Create User Mapping
Use the CREATE USER MAPPING
command to establish a mapping between a local user and a foreign server. Syntax:
local_user
: Designation of the local database user name.server_name
: The designation of the foreign server established in the preceding step.OPTIONS
: Theoption
will have varying parameter options depending on the foreign data source.
Creating a Foreign Table
Use the CREATE FOREIGN TABLE
command to establish a foreign table. Syntax:
table_name
: Indicates the name of the table.column_name
: The names of the columns and their data types in the specified foreign table must align with the structure of the external file. For guidance on data type mapping, consult the relevant documentation.server_name
: Refers to the name of the previously created foreign server.OPTIONS
: Theoption
may contain various parameters based on the features of the external data storage.
Creating and Refreshing Foreign Tables in Batches
The IMPORT FOREIGN SCHEMA
command allows for the batch creation and updating of foreign tables. This is particularly useful for data sources with external metadata management systems, like MaxCompute and Glue. Syntax:
foreign_schema
: A foreign data source corresponding to the schema.table
: Specify the table name whose metadata is desired for import or update. All tables under the schema will be imported without restrictions. However, importing many tables may extend the process duration.server_name
: The designation of the foreign server previously established.local_schema
: The table metadata is retained within the corresponding local schema.
To explore more syntax, refer to IMPORT FOREIGN SCHEMA.
Querying a Foreign Table
Once you've created a table, you can query it like a regular one. The data within the table is sourced from the linked external file, and its content is dynamically read during the query process:
Notices
- Ensure Tacnode has permission to read the external file/database.
- Changes made to external files or databases will not automatically sync with the foreign table. To refresh it, recreate the foreign table or use the
IMPORT FOREIGN SCHEMA
command. - Currently, write operations (INSERT, UPDATE, DELETE) on foreign tables are not supported.
- The foreign table's performance depends on the size and access speed of the external file, which may require optimization for larger files.
- Unsupported type mappings include: Parquet's struct type cannot be directly converted to JSONB. Using text storage and then casting it to the JSONB type is advisable.
File-based Foreign Table
Learn how to efficiently manage foreign tables in S3, and Object Store with our comprehensive guide, enhancing your data integration and access strategies.
AWS Glue Foreign Table
Learn how to integrate AWS Glue with foreign tables in Tacnode. Discover step-by-step guides to enhance your data management and analytics capabilities.