@@ -418,6 +418,13 @@ class TKiSinkTypeAnnotationTransformer : public TKiSinkVisitorTransformer
418
418
THashSet<TString> generateColumnsIfInsertColumnsSet;
419
419
420
420
for (const auto & [name, info] : table->Metadata ->Columns ) {
421
+ if (info.IsBuildInProgress && rowType->FindItem (name)) {
422
+ ctx.AddError (YqlIssue (pos, TIssuesIds::KIKIMR_BAD_REQUEST, TStringBuilder ()
423
+ << " Column is under build operation, write operation is not allowed to column: " << name
424
+ << " for table: " << table->Metadata ->Name ));
425
+ return TStatus::Error;
426
+ }
427
+
421
428
if (rowType->FindItem (name)) {
422
429
continue ;
423
430
}
@@ -431,7 +438,7 @@ class TKiSinkTypeAnnotationTransformer : public TKiSinkVisitorTransformer
431
438
}
432
439
433
440
if (info.IsDefaultKindDefined ()) {
434
- if (op == TYdbOperation::Upsert) {
441
+ if (op == TYdbOperation::Upsert && !info. IsBuildInProgress ) {
435
442
generateColumnsIfInsertColumnsSet.emplace (name);
436
443
}
437
444
@@ -625,6 +632,13 @@ class TKiSinkTypeAnnotationTransformer : public TKiSinkVisitorTransformer
625
632
<< " Column '" << item->GetName () << " ' does not exist in table '" << node.Table ().Value () << " '." ));
626
633
return TStatus::Error;
627
634
}
635
+
636
+ if (column->IsBuildInProgress ) {
637
+ ctx.AddError (YqlIssue (ctx.GetPosition (node.Pos ()), TIssuesIds::KIKIMR_BAD_REQUEST, TStringBuilder ()
638
+ << " Column '" << item->GetName () << " ' is under the build operation '" << node.Table ().Value () << " '." ));
639
+ return TStatus::Error;
640
+ }
641
+
628
642
if (column->NotNull && item->HasOptionalOrNull ()) {
629
643
if (item->GetItemType ()->GetKind () == ETypeAnnotationKind::Pg) {
630
644
// no type-level notnull check for pg types.
@@ -636,6 +650,8 @@ class TKiSinkTypeAnnotationTransformer : public TKiSinkVisitorTransformer
636
650
}
637
651
}
638
652
653
+
654
+
639
655
if (!node.ReturningColumns ().Empty ()) {
640
656
ctx.AddError (TIssue (ctx.GetPosition (node.Pos ()), TStringBuilder ()
641
657
<< " It is not allowed to use returning" ));
@@ -808,7 +824,13 @@ virtual TStatus HandleCreateTable(TKiCreateTable create, TExprContext& ctx) over
808
824
809
825
columnMeta.SetDefaultFromLiteral ();
810
826
811
- if (auto pgConst = constraint.Value ().Maybe <TCoPgConst>()) {
827
+ YQL_ENSURE (constraint.Value ().IsValid ());
828
+ const auto & constrValue = constraint.Value ().Cast ();
829
+ bool isPgNull = constrValue.Ptr ()->IsCallable () &&
830
+ constrValue.Ptr ()->Content () == " PgCast" && constrValue.Ptr ()->ChildrenSize () >= 1 &&
831
+ constrValue.Ptr ()->Child (0 )->IsCallable () && constrValue.Ptr ()->Child (0 )->Content () == " Null" ;
832
+
833
+ if (constrValue.Maybe <TCoPgConst>() || isPgNull) {
812
834
auto actualPgType = actualType->Cast <TPgExprType>();
813
835
YQL_ENSURE (actualPgType);
814
836
@@ -819,25 +841,38 @@ virtual TStatus HandleCreateTable(TKiCreateTable create, TExprContext& ctx) over
819
841
return TStatus::Error;
820
842
}
821
843
822
- TString content = TString (pgConst.Cast ().Value ().Value ());
823
- auto parseResult = NKikimr::NPg::PgNativeBinaryFromNativeText (content, typeDesc);
824
- if (parseResult.Error ) {
825
- ctx.AddError (TIssue (ctx.GetPosition (constraint.Pos ()),
826
- TStringBuilder () << " Failed to parse default expr for typename " << actualPgType->GetName ()
827
- << " , error reason: " << *parseResult.Error ));
828
- return TStatus::Error;
844
+ if (isPgNull) {
845
+ if (columnMeta.NotNull ) {
846
+ ctx.AddError (TIssue (ctx.GetPosition (constraint.Pos ()), TStringBuilder () << " Default expr " << columnName
847
+ << " is nullable or optional, but column has not null constraint. " ));
848
+ return TStatus::Error;
849
+ }
850
+
851
+ columnMeta.DefaultFromLiteral .mutable_value ()->set_null_flag_value (NProtoBuf::NULL_VALUE);
852
+
853
+ } else {
854
+ YQL_ENSURE (constrValue.Maybe <TCoPgConst>());
855
+ auto pgConst = constrValue.Cast <TCoPgConst>();
856
+ TString content = TString (pgConst.Value ().Value ());
857
+ auto parseResult = NKikimr::NPg::PgNativeBinaryFromNativeText (content, typeDesc);
858
+ if (parseResult.Error ) {
859
+ ctx.AddError (TIssue (ctx.GetPosition (constraint.Pos ()),
860
+ TStringBuilder () << " Failed to parse default expr for typename " << actualPgType->GetName ()
861
+ << " , error reason: " << *parseResult.Error ));
862
+ return TStatus::Error;
863
+ }
864
+
865
+ columnMeta.DefaultFromLiteral .mutable_value ()->set_bytes_value (parseResult.Str );
829
866
}
830
867
831
- columnMeta.DefaultFromLiteral .mutable_value ()->set_bytes_value (parseResult.Str );
832
868
auto * pg = columnMeta.DefaultFromLiteral .mutable_type ()->mutable_pg_type ();
833
-
834
869
pg->set_type_name (NKikimr::NPg::PgTypeNameFromTypeDesc (typeDesc));
835
870
pg->set_oid (NKikimr::NPg::PgTypeIdFromTypeDesc (typeDesc));
836
- } else if (auto literal = constraint. Value () .Maybe <TCoDataCtor>()) {
837
- FillLiteralProto (constraint. Value (). Cast <TCoDataCtor> (), columnMeta.DefaultFromLiteral );
871
+ } else if (auto literal = constrValue .Maybe <TCoDataCtor>()) {
872
+ FillLiteralProto (literal. Cast (), columnMeta.DefaultFromLiteral );
838
873
} else {
839
874
ctx.AddError (TIssue (ctx.GetPosition (constraint.Pos ()),
840
- TStringBuilder () << " Unsupported type of default value " << constraint. Value (). Cast (). Ptr ()-> Content () ));
875
+ TStringBuilder () << " Unsupported type of default value" ));
841
876
return TStatus::Error;
842
877
}
843
878
0 commit comments