@@ -418,6 +418,13 @@ class TKiSinkTypeAnnotationTransformer : public TKiSinkVisitorTransformer
418418 THashSet<TString> generateColumnsIfInsertColumnsSet;
419419
420420 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+
421428 if (rowType->FindItem (name)) {
422429 continue ;
423430 }
@@ -431,7 +438,7 @@ class TKiSinkTypeAnnotationTransformer : public TKiSinkVisitorTransformer
431438 }
432439
433440 if (info.IsDefaultKindDefined ()) {
434- if (op == TYdbOperation::Upsert) {
441+ if (op == TYdbOperation::Upsert && !info. IsBuildInProgress ) {
435442 generateColumnsIfInsertColumnsSet.emplace (name);
436443 }
437444
@@ -625,6 +632,13 @@ class TKiSinkTypeAnnotationTransformer : public TKiSinkVisitorTransformer
625632 << " Column '" << item->GetName () << " ' does not exist in table '" << node.Table ().Value () << " '." ));
626633 return TStatus::Error;
627634 }
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+
628642 if (column->NotNull && item->HasOptionalOrNull ()) {
629643 if (item->GetItemType ()->GetKind () == ETypeAnnotationKind::Pg) {
630644 // no type-level notnull check for pg types.
@@ -636,6 +650,8 @@ class TKiSinkTypeAnnotationTransformer : public TKiSinkVisitorTransformer
636650 }
637651 }
638652
653+
654+
639655 if (!node.ReturningColumns ().Empty ()) {
640656 ctx.AddError (TIssue (ctx.GetPosition (node.Pos ()), TStringBuilder ()
641657 << " It is not allowed to use returning" ));
@@ -808,7 +824,13 @@ virtual TStatus HandleCreateTable(TKiCreateTable create, TExprContext& ctx) over
808824
809825 columnMeta.SetDefaultFromLiteral ();
810826
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) {
812834 auto actualPgType = actualType->Cast <TPgExprType>();
813835 YQL_ENSURE (actualPgType);
814836
@@ -819,25 +841,38 @@ virtual TStatus HandleCreateTable(TKiCreateTable create, TExprContext& ctx) over
819841 return TStatus::Error;
820842 }
821843
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 );
829866 }
830867
831- columnMeta.DefaultFromLiteral .mutable_value ()->set_bytes_value (parseResult.Str );
832868 auto * pg = columnMeta.DefaultFromLiteral .mutable_type ()->mutable_pg_type ();
833-
834869 pg->set_type_name (NKikimr::NPg::PgTypeNameFromTypeDesc (typeDesc));
835870 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 );
838873 } else {
839874 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" ));
841876 return TStatus::Error;
842877 }
843878
0 commit comments