Skip to content

Add ability to create defaults from aliases - #9489

Merged
alexey-milovidov merged 5 commits into
masterfrom
default_on_aliases
Mar 6, 2020
Merged

alexey-milovidov merged 5 commits into
masterfrom
default_on_aliases

Conversation

@alesapin

@alesapin alesapin commented Mar 3, 2020 •

Copy link
Copy Markdown
Member

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

Changelog category (leave one):

  • Bug Fix

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Now it's possible to create a column with DEFAULT expression which depends on a column with default ALIAS expression.

Fixes #2283 #8603

@alesapin

alesapin commented Mar 3, 2020

Copy link
Copy Markdown
Member Author

Merge after #9481.

@alesapin alesapin added the pr-bugfix Pull request with bugfix, not backported by default label Mar 3, 2020
@qoega

qoega commented Mar 4, 2020

Copy link
Copy Markdown
Member

@filimonov

filimonov commented Mar 4, 2020 •

Copy link
Copy Markdown
Contributor

Not clear what with complicated aliases / defaults which depend on other aliases / defaults etc, maybe test for that?

I.e. something like

create table test (
  a1 UInt64 DEFAULT a+1,
  a1 UInt64 DEFAULT a+1,
  a2 UInt64 DEFAULT a3+a4,
  a3 UInt64 DEFAULT a2+1,
  a4 UInt64 ALIAS      a3+1
) Engine=Log;


-- here if any 2 columns are provided in insert third can be calculated. 
creare table pythagoras (
  a Float64 DEFAULT sqrt(c*c - b*b),
  b Float64 DEFAULT sqrt(c*c - a*a),
  c Float64 DEFAULT sqrt(a*a + b*b)
) Engine=Log;

That's not very clear how it should behave with circular references (as depending on columns provided at insert it can be resolvable or not), it seems the simplest option would be just to forbid such scenarios explicitly, but i'm not 100% sure.

Can you check how it works / create a test for that?

@alexey-milovidov

Copy link
Copy Markdown
Member
CREATE TABLE test (a DEFAULT b, b DEFAULT a) ENGINE = Memory

It works!

... and what are the types of a and b?

@alexey-milovidov

Copy link
Copy Markdown
Member

I will add a test with cyclic aliases and explicit types.
Then @alesapin will prohibit cyclic aliases with unknown types.

@alexey-milovidov

Copy link
Copy Markdown
Member

But it does not work if I specify data types.

@alexey-milovidov

Copy link
Copy Markdown
Member

@filimonov Your queries don't work. I will add a test to ensure that they don't work.

@alexey-milovidov

Copy link
Copy Markdown
Member

Will merge and then fix the case of

CREATE TABLE test (a DEFAULT b, b DEFAULT a) ENGINE = Memory

In a separate PR.

@alexey-milovidov

alexey-milovidov commented Mar 5, 2020 •

Copy link
Copy Markdown
Member

@alesapin I think that we can permit tables like this:

CREATE TABLE default.test (`a` String DEFAULT b, `b` String DEFAULT a) ENGINE = Memory

To allow a user to insert one or another column. This have its use.

@alexey-milovidov

Copy link
Copy Markdown
Member

CREATE TABLE test (a DEFAULT b, b DEFAULT a) ENGINE = Memory

I can execute this query and it will prevent the server to start!

@alexey-milovidov
alexey-milovidov merged commit ff4204a into master Mar 6, 2020
@alexey-milovidov
alexey-milovidov deleted the default_on_aliases branch March 6, 2020 00:25
@filimonov

Copy link
Copy Markdown
Contributor

Maybe we should make a note in changelog - just in case if somebody was using circular aliases.

@alesapin

Copy link
Copy Markdown
Member Author

CREATE TABLE test (a DEFAULT b, b DEFAULT a) ENGINE = Memory

I can execute this query and it will prevent the server to start!

#9603 Fix is here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-docs-needed pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't use alias columns in default expressions

5 participants