-
Notifications
You must be signed in to change notification settings - Fork 646
support cast in default values #1754
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
Merged
gridnevvvit
merged 1 commit into
ydb-platform:main
from
gridnevvvit:support-casts-in-default-values
Feb 9, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -808,7 +808,13 @@ virtual TStatus HandleCreateTable(TKiCreateTable create, TExprContext& ctx) over | |
|
||
columnMeta.SetDefaultFromLiteral(); | ||
|
||
if (auto pgConst = constraint.Value().Maybe<TCoPgConst>()) { | ||
YQL_ENSURE(constraint.Value().IsValid()); | ||
const auto& constrValue = constraint.Value().Cast(); | ||
bool isPgNull = constrValue.Ptr()->IsCallable() && | ||
constrValue.Ptr()->Content() == "PgCast" && constrValue.Ptr()->ChildrenSize() >= 1 && | ||
constrValue.Ptr()->Child(0)->IsCallable() && constrValue.Ptr()->Child(0)->Content() == "Null"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Думаю, тут нужен case insensitive match по "Null". И круто быэто в отдельную функцию вытащить |
||
|
||
if (constrValue.Maybe<TCoPgConst>() || isPgNull) { | ||
auto actualPgType = actualType->Cast<TPgExprType>(); | ||
YQL_ENSURE(actualPgType); | ||
|
||
|
@@ -819,25 +825,38 @@ virtual TStatus HandleCreateTable(TKiCreateTable create, TExprContext& ctx) over | |
return TStatus::Error; | ||
} | ||
|
||
TString content = TString(pgConst.Cast().Value().Value()); | ||
auto parseResult = NKikimr::NPg::PgNativeBinaryFromNativeText(content, typeDesc); | ||
if (parseResult.Error) { | ||
ctx.AddError(TIssue(ctx.GetPosition(constraint.Pos()), | ||
TStringBuilder() << "Failed to parse default expr for typename " << actualPgType->GetName() | ||
<< ", error reason: " << *parseResult.Error)); | ||
return TStatus::Error; | ||
if (isPgNull) { | ||
if (columnMeta.NotNull) { | ||
ctx.AddError(TIssue(ctx.GetPosition(constraint.Pos()), TStringBuilder() << "Default expr " << columnName | ||
<< " is nullable or optional, but column has not null constraint. ")); | ||
return TStatus::Error; | ||
} | ||
|
||
columnMeta.DefaultFromLiteral.mutable_value()->set_null_flag_value(NProtoBuf::NULL_VALUE); | ||
|
||
} else { | ||
YQL_ENSURE(constrValue.Maybe<TCoPgConst>()); | ||
auto pgConst = constrValue.Cast<TCoPgConst>(); | ||
TString content = TString(pgConst.Value().Value()); | ||
auto parseResult = NKikimr::NPg::PgNativeBinaryFromNativeText(content, typeDesc); | ||
if (parseResult.Error) { | ||
ctx.AddError(TIssue(ctx.GetPosition(constraint.Pos()), | ||
TStringBuilder() << "Failed to parse default expr for typename " << actualPgType->GetName() | ||
<< ", error reason: " << *parseResult.Error)); | ||
return TStatus::Error; | ||
} | ||
|
||
columnMeta.DefaultFromLiteral.mutable_value()->set_bytes_value(parseResult.Str); | ||
} | ||
|
||
columnMeta.DefaultFromLiteral.mutable_value()->set_bytes_value(parseResult.Str); | ||
auto* pg = columnMeta.DefaultFromLiteral.mutable_type()->mutable_pg_type(); | ||
|
||
pg->set_type_name(NKikimr::NPg::PgTypeNameFromTypeDesc(typeDesc)); | ||
pg->set_oid(NKikimr::NPg::PgTypeIdFromTypeDesc(typeDesc)); | ||
} else if (auto literal = constraint.Value().Maybe<TCoDataCtor>()) { | ||
FillLiteralProto(constraint.Value().Cast<TCoDataCtor>(), columnMeta.DefaultFromLiteral); | ||
} else if (auto literal = constrValue.Maybe<TCoDataCtor>()) { | ||
FillLiteralProto(literal.Cast(), columnMeta.DefaultFromLiteral); | ||
} else { | ||
ctx.AddError(TIssue(ctx.GetPosition(constraint.Pos()), | ||
TStringBuilder() << "Unsupported type of default value " << constraint.Value().Cast().Ptr()->Content())); | ||
TStringBuilder() << "Unsupported type of default value")); | ||
return TStatus::Error; | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вроде норм, но не до конца есть понимание нужно ли тут настолько strict условие. Что если просто проверить, что если там не data consturctor, то навесить EvaluateExpr?