hongkunxu opened a new pull request, #20187:
URL: https://github.com/apache/pinot/pull/20187

   ## Summary
   
   Creating a table from an existing Pinot definition currently requires 
manually copying and renaming its schema and table configs. This PR adds 
`CREATE TABLE ... LIKE ...` through the Controller’s `POST /sql/ddl` endpoint.
   
   ## Syntax
   
   Creates a new table by copying an existing table’s persisted schema and 
table configuration definitions.
   
   ```sql
   CREATE TABLE [IF NOT EXISTS] [target_database.]new_table
   LIKE [source_database.]existing_table
   [TYPE { OFFLINE | REALTIME }];
   ```
   
   - `new_table`: Name of the table to create.
   - `existing_table`: Source table whose definition is copied.
   - `IF NOT EXISTS`: Return a no-op when any target variant already exists.
   - `target_database` / `source_database`: Optional, independent database 
qualifiers. Cross-database copying is supported within the same cluster.
   - `TYPE`: Select a single source variant. When omitted, copy every existing 
source variant, preserving OFFLINE, REALTIME, or hybrid shape.
   
   Both table names must be raw names without `_OFFLINE` or `_REALTIME` 
suffixes.
   
   ## Examples
   
   ```sql
   -- Copy all source variants.
   CREATE TABLE events_copy LIKE events;
   
   -- Copy only the OFFLINE variant.
   CREATE TABLE IF NOT EXISTS offline_copy LIKE events TYPE OFFLINE;
   
   -- Copy a table across databases.
   CREATE TABLE archive.events_copy LIKE production.events;
   ```
   
   ## Behavior
   
   - Deep-copy the persisted schema and table configs, rename their structural 
identities, and apply normal target-side tuning and validation.
   - Support dry-run through `POST /sql/ddl?dryRun=true`.
   - Existing targets are never extended or repaired by `IF NOT EXISTS`.
   - Reject unreadable selected source configs before creating any target 
resources.
   - Copy definitions without copying existing segments, stream offsets, or 
runtime state. REALTIME targets start normal ingestion using the inherited 
configuration.
   
   Hybrid creation validates both variants before writing, then creates them 
sequentially. On failure, completed resources are retained and reported in 
`createdTables`; creation is not atomic.
   
   Materialized views and Pinot logical-table objects are excluded from this 
initial implementation.
   
   ## Testing
   
   - Parser/compiler tests cover syntax, qualification, type selection, and DDL 
classification.
   - Metadata and Controller tests cover source shapes, deep-copy isolation, 
authorization, dry-run, partial failures, and unreadable source configs.
   - REST integration tests verify persistence, idempotence, placeholder 
preservation, and rejection of malformed metadata before writes.
   - Confirmed the malformed-source regression fails with the previous behavior 
and passes with the fix.
   - Spotless, Checkstyle, and license checks pass.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to