Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CREATE FOREIGN TABLE LIKE. #554

Merged
merged 1 commit into from
Aug 7, 2024

Conversation

avamingli
Copy link
Contributor

Allow user to use LIKE to create foreign tables, ex:

CREATE FOREIGN TABLE ft(LIKE t1);

Foreign table ft will use t1's column definitions as its own.

In CBDB, we usually use foreign tables to import data from outside data source.
Each target table usually has an associated foreign table.
This is very useful if target table has a lot of columns, making it easy to create a foreign table without defining columns one by one, and avoid mistake.

Distribution policy is not inherited for this case because it should be defined with options by users.

CREATE FOREIGN DATA WRAPPER dummy;
CREATE SERVER s0 FOREIGN DATA WRAPPER dummy;
CREATE TABLE ft_source_table(a INT, b INT, c INT) DISTRIBUTED BY (b);
CREATE FOREIGN TABLE ft_like (LIKE ft_source_table) SERVER s0; 
\d+ ft_like
                                     Foreign table "public.ft_like"
 Column |  Type   | Collation | Nullable | Default | FDW options | Storage | Stats target | Description 
--------+---------+-----------+----------+---------+-------------+---------+--------------+-------------
 a      | integer |           |          |         |             | plain   |              | 
 b      | integer |           |          |         |             | plain   |              | 
 c      | integer |           |          |         |             | plain   |              | 
Server: s0

Authored-by: Zhang Mingli avamingli@gmail.com

fix #ISSUE_Number


Change logs

Describe your change clearly, including what problem is being solved or what feature is being added.

If it has some breaking backward or forward compatibility, please clary.

Why are the changes needed?

Describe why the changes are necessary.

Does this PR introduce any user-facing change?

If yes, please clarify the previous behavior and the change this PR proposes.

How was this patch tested?

Please detail how the changes were tested, including manual tests and any relevant unit or integration tests.

Contributor's Checklist

Here are some reminders and checklists before/when submitting your pull request, please check them:

  • Make sure your Pull Request has a clear title and commit message. You can take git-commit template as a reference.
  • Sign the Contributor License Agreement as prompted for your first-time contribution(One-time setup).
  • Learn the coding contribution guide, including our code conventions, workflow and more.
  • List your communication in the GitHub Issues or Discussions (if has or needed).
  • Document changes.
  • Add tests for the change
  • Pass make installcheck
  • Pass make -C src/test installcheck-cbdb-parallel
  • Feel free to request cloudberrydb/dev team for review and approval when your PR is ready🥳

Allow user to use LIKE to create foreign tables, ex:
CREATE FOREIGN TABLE ft(LIKE t1);
Foreign table ft will use t1's column definitions as its own.

In CBDB, we usually use foreign tables to import data from outside
data source.
Each target table usually has an associated foreign table.
This is very useful if target table has a lot of columns, making
it easy to create a foreign table without defining columns
one by one, and avoid mistake.

Distribution policy is not inherited for this case because it
should be defined with options by users.

Authored-by: Zhang Mingli avamingli@gmail.com
@avamingli avamingli force-pushed the create_foreign_table_like branch from 46520ce to 3d0987f Compare August 6, 2024 13:38
@avamingli avamingli merged commit 4122a93 into apache:main Aug 7, 2024
11 checks passed
@avamingli avamingli deleted the create_foreign_table_like branch August 7, 2024 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants