Skip to content

branch-4.2: [fix](variant) Make default_variant_* session variables test-only and fix CREATE TABLE LIKE of VARIANT #70501 - #70609

Open
csun5285 wants to merge 1 commit into
apache:branch-4.2from
csun5285:pick-70501-branch-4.2
Open

csun5285 wants to merge 1 commit into
apache:branch-4.2from
csun5285:pick-70501-branch-4.2

Conversation

@csun5285

Copy link
Copy Markdown
Contributor

Cherry-picked from #70501

What problem does this PR solve?

Issue Number: None

Related PR: #70501

Problem Summary:

CREATE TABLE LIKE prints the source table as DDL text (the SHOW CREATE TABLE text) and parses it again. The text of a VARIANT column omits variant_enable_doc_mode and variant_enable_nested_group when they are false, and the parser fills every property missing from a DDL from the default_variant_* session variables. So the copy depended on the session that ran the statement:

CREATE TABLE src (id INT, v VARIANT<'a.b':INT, PROPERTIES("variant_max_subcolumns_count"="3")>)
DUPLICATE KEY(id) DISTRIBUTED BY HASH(id) BUCKETS 1 PROPERTIES("replication_num"="1");
SET default_variant_enable_doc_mode = true;
CREATE TABLE dst LIKE src;
SHOW CREATE TABLE dst;
-- before: v variant<MATCH_NAME 'a.b':int,PROPERTIES ("variant_enable_doc_mode" = "true",
--         "variant_doc_materialization_min_rows" = "0","variant_doc_hash_shard_count" = "64")>
--         (doc mode, the subcolumn count 3 is gone)
-- after:  the SET fails; with the default session v is as in src

The default_variant_* session variables exist for the fuzzy tests only. Fix:

  1. The parser reads the default_variant_* session variables only when the FE runs with enable_debug_points = true, which every regression pipeline and docker test cluster sets. Otherwise, and without a session, the properties a DDL leaves out take the built-in values (a parse without a session used its own constants before, such as subcolumn count 0 and nested group on). It does not use the global values either: a value set with SET GLOBAL on an older version still loads from an image. So a DDL text, such as the one CREATE TABLE LIKE prints and parses, creates the same column in every session.
  2. The variables are invisible in SHOW VARIABLES, and SET / SET GLOBAL / SET_VAR of them fails unless debug points are enabled. Users state VARIANT properties in the column definition.
  3. A nested group VARIANT type prints only variant_enable_nested_group, as a doc mode type prints only the doc mode properties.

With debug points enabled, CREATE TABLE LIKE still follows the session; a test that copies a VARIANT table sets the variables first, as the existing suites do.

Release note

The default_variant_* session variables
(default_variant_max_subcolumns_count,
default_variant_enable_typed_paths_to_sparse,
default_variant_max_sparse_column_statistics_size, default_variant_sparse_hash_shard_count,
default_variant_enable_doc_mode,
default_variant_doc_materialization_min_rows,
default_variant_doc_hash_shard_count,
default_variant_enable_nested_group) can no longer be set and are not shown by SHOW VARIABLES; set the properties in the VARIANT column definition instead. A value set with SET GLOBAL before the upgrade no longer takes effect. CREATE TABLE LIKE copies the VARIANT properties of the source table regardless of the session.

Differences from the master commit, all because branch-4.2 lacks later refactors:

  • SessionVariable uses VariableMgr.INVISIBLE (there is no VarAttrDef).
  • VariableMgrTest checks VariableMgr.dump instead of VariableMgr.getShownVarContext, which branch-4.2 does not have.
  • CreateTableLikeTest, TypeTest and VariableMgrTest are JUnit 4 on branch-4.2, so the new cases use its assertions and helpers.

Check List (For Author)

  • Test: Unit Test
    • CreateTableLikeTest, TypeTest, PropertyAnalyzerTest, NereidsParserTest and VariableMgrTest pass on branch-4.2 (145 cases). The regression suite test_variant_create_table_like was not run on branch-4.2.
  • Behavior changed: Yes (see the release note)
  • Does this need documentation: No

(cherry picked from commit 0e8b56e)

Background

What problem does this PR solve?

Issue Number:
Related PR:
PR Type:

Problem Summary:

Details

Testing

Notes for Reviewers

Release note

Check List (For Author)

  • Behavior changed:
  • Does this need documentation:
  • Pre-submission status:

AI Disclosure

  • Tool:
  • Generated:
  • Human review:

…est-only and fix CREATE TABLE LIKE of VARIANT apache#70501

Cherry-picked from apache#70501

### What problem does this PR solve?

Issue Number: None

Related PR: apache#70501

Problem Summary:

CREATE TABLE LIKE prints the source table as DDL text (the SHOW CREATE
TABLE text) and parses it again. The text of a VARIANT column omits
`variant_enable_doc_mode` and `variant_enable_nested_group` when they
are false, and the parser fills every property missing from a DDL from
the `default_variant_*` session variables. So the copy depended on the
session that ran the statement:

```sql
CREATE TABLE src (id INT, v VARIANT<'a.b':INT, PROPERTIES("variant_max_subcolumns_count"="3")>)
DUPLICATE KEY(id) DISTRIBUTED BY HASH(id) BUCKETS 1 PROPERTIES("replication_num"="1");
SET default_variant_enable_doc_mode = true;
CREATE TABLE dst LIKE src;
SHOW CREATE TABLE dst;
-- before: v variant<MATCH_NAME 'a.b':int,PROPERTIES ("variant_enable_doc_mode" = "true",
--         "variant_doc_materialization_min_rows" = "0","variant_doc_hash_shard_count" = "64")>
--         (doc mode, the subcolumn count 3 is gone)
-- after:  the SET fails; with the default session v is as in src
```

The `default_variant_*` session variables exist for the fuzzy tests
only. Fix:
1. The parser reads the `default_variant_*` session variables only when
the FE runs with `enable_debug_points = true`, which every regression
pipeline and docker test cluster sets. Otherwise, and without a session,
the properties a DDL leaves out take the built-in values (a parse
without a session used its own constants before, such as subcolumn count
0 and nested group on). It does not use the global values either: a
value set with SET GLOBAL on an older version still loads from an image.
So a DDL text, such as the one CREATE TABLE LIKE prints and parses,
creates the same column in every session.
2. The variables are invisible in SHOW VARIABLES, and SET / SET GLOBAL /
SET_VAR of them fails unless debug points are enabled. Users state
VARIANT properties in the column definition.
3. A nested group VARIANT type prints only
`variant_enable_nested_group`, as a doc mode type prints only the doc
mode properties.

With debug points enabled, CREATE TABLE LIKE still follows the session;
a test that copies a VARIANT table sets the variables first, as the
existing suites do.

### Release note

The `default_variant_*` session variables
(`default_variant_max_subcolumns_count`,
`default_variant_enable_typed_paths_to_sparse`,
`default_variant_max_sparse_column_statistics_size`,
`default_variant_sparse_hash_shard_count`,
`default_variant_enable_doc_mode`,
`default_variant_doc_materialization_min_rows`,
`default_variant_doc_hash_shard_count`,
`default_variant_enable_nested_group`) can no longer be set and are not
shown by SHOW VARIABLES; set the properties in the VARIANT column
definition instead. A value set with SET GLOBAL before the upgrade no
longer takes effect. CREATE TABLE LIKE copies the VARIANT properties of
the source table regardless of the session.

Differences from the master commit, all because branch-4.2 lacks later
refactors:
- `SessionVariable` uses `VariableMgr.INVISIBLE` (there is no `VarAttrDef`).
- `VariableMgrTest` checks `VariableMgr.dump` instead of
  `VariableMgr.getShownVarContext`, which branch-4.2 does not have.
- `CreateTableLikeTest`, `TypeTest` and `VariableMgrTest` are JUnit 4 on
  branch-4.2, so the new cases use its assertions and helpers.

### Check List (For Author)

- Test: Unit Test
    - CreateTableLikeTest, TypeTest, PropertyAnalyzerTest, NereidsParserTest and VariableMgrTest pass on branch-4.2 (145 cases). The regression suite test_variant_create_table_like was not run on branch-4.2.
- Behavior changed: Yes (see the release note)
- Does this need documentation: No

(cherry picked from commit 0e8b56e)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@csun5285
csun5285 requested a review from yiguolei as a code owner November 16, 2026 06:24
@csun5285

Copy link
Copy Markdown
Contributor Author

run buildall

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.

1 participant