Skip to content

Commit 1ca45e2

Browse files
author
mpereskokova
committed
Rename Upsert to Replace
То, что было `UPSERT`-ом на самом деле работает как `REPLACE` - возвращаю справедливость. commit_hash:3b4cdd5bcf3957f68be4ab648e399e8dc923d48f
1 parent e64a67e commit 1ca45e2

27 files changed

+52
-61
lines changed

yql/essentials/sql/v1/query.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3055,8 +3055,8 @@ TNodePtr BuildAlterTransfer(TPosition pos, const TString& id, std::optional<TStr
30553055
static const TMap<EWriteColumnMode, TString> columnModeToStrMapMR{
30563056
{EWriteColumnMode::Default, ""},
30573057
{EWriteColumnMode::Insert, "append"},
3058-
{EWriteColumnMode::Upsert, "upsert"},
3059-
{EWriteColumnMode::Renew, "renew"}};
3058+
{EWriteColumnMode::Renew, "renew"}, // insert with truncat
3059+
{EWriteColumnMode::Replace, "replace"}};
30603060

30613061
static const TMap<EWriteColumnMode, TString> columnModeToStrMapStat{
30623062
{EWriteColumnMode::Upsert, "upsert"}};

yql/essentials/sql/v1/sql_into_tables.cpp

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -232,23 +232,10 @@ bool TSqlIntoTable::ValidateServiceName(const TRule_into_table_stmt& node, const
232232
const bool isStat = serviceName == StatProviderName;
233233

234234
if (!isKikimr) {
235-
if (mode == ESQLWriteColumnMode::UpsertInto && !isStat && isMapReduce)
236-
{
237-
// Upsert in MapReduce is available only from 2025.4
238-
auto requiredLangVer = MakeLangVersion(2025, 4);
239-
if (!IsBackwardCompatibleFeatureAvailable(requiredLangVer)) {
240-
auto str = FormatLangVersion(requiredLangVer);
241-
YQL_ENSURE(str);
242-
Ctx_.Error(pos) << "UPSERT is not available before language version " << *str;
243-
Ctx_.IncrementMonCounter("sql_errors", TStringBuilder() << "UPSERT is not available before language version " << *str);
244-
return false;
245-
}
246-
}
247-
248235
if (mode == ESQLWriteColumnMode::InsertOrAbortInto ||
249236
mode == ESQLWriteColumnMode::InsertOrIgnoreInto ||
250237
mode == ESQLWriteColumnMode::InsertOrRevertInto ||
251-
mode == ESQLWriteColumnMode::UpsertInto && !isStat && !isMapReduce)
238+
mode == ESQLWriteColumnMode::UpsertInto && !isStat)
252239
{
253240
Ctx_.Error(pos) << SqlIntoUserModeStr_ << " is not supported for " << serviceName << " tables";
254241
Ctx_.IncrementMonCounter("sql_errors", TStringBuilder() << SqlIntoUserModeStr_ << "UnsupportedFor" << serviceName);
@@ -258,9 +245,11 @@ bool TSqlIntoTable::ValidateServiceName(const TRule_into_table_stmt& node, const
258245

259246
if (isMapReduce) {
260247
if (mode == ESQLWriteColumnMode::ReplaceInto) {
261-
Ctx_.Error(pos) << "Meaning of REPLACE INTO has been changed, now you should use INSERT INTO <table> WITH TRUNCATE ... for " << serviceName;
262-
Ctx_.IncrementMonCounter("sql_errors", "ReplaceIntoConflictUsage");
263-
return false;
248+
auto requiredLangVer = MakeLangVersion(2025, 4);
249+
if (!IsBackwardCompatibleFeatureAvailable(requiredLangVer)) {
250+
Ctx_.Error(pos) << "REPLACE is not available before language version " << FormatLangVersion(requiredLangVer);
251+
return false;
252+
}
264253
}
265254
} else if (isKikimr) {
266255
if (mode == ESQLWriteColumnMode::InsertIntoWithTruncate) {

yql/essentials/sql/v1/sql_ut_common.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5671,21 +5671,23 @@ Y_UNIT_TEST(InsertAbortMapReduce) {
56715671
Y_UNIT_TEST(ReplaceIntoMapReduce) {
56725672
NYql::TAstParseResult res = SqlToYql("REPLACE INTO plato.Output SELECT key FROM plato.Input");
56735673
UNIT_ASSERT(!res.Root);
5674-
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:0: Error: Meaning of REPLACE INTO has been changed, now you should use INSERT INTO <table> WITH TRUNCATE ... for yt\n");
5675-
}
5676-
5677-
Y_UNIT_TEST(UpsertIntoMapReduce) {
5678-
NYql::TAstParseResult res = SqlToYql("UPSERT INTO plato.Output SELECT key FROM plato.Input");
5679-
UNIT_ASSERT(!res.Root);
5680-
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:0: Error: UPSERT is not available before language version 2025.04\n");
5674+
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:0: Error: REPLACE is not available before language version 2025.04\n");
56815675

56825676
NSQLTranslation::TTranslationSettings settings;
56835677
settings.LangVer = NYql::MakeLangVersion(2025, 4);
56845678

5685-
res = SqlToYqlWithSettings("UPSERT INTO plato.Output SELECT key FROM plato.Input", settings);
5679+
res = SqlToYqlWithSettings("REPLACE INTO plato.Output SELECT key FROM plato.Input", settings);
56865680
UNIT_ASSERT_C(res.IsOk(), res.Issues.ToOneLineString());
56875681
}
56885682

5683+
Y_UNIT_TEST(UpsertIntoMapReduce) {
5684+
NYql::TAstParseResult res = SqlToYql(R"sql(
5685+
UPSERT INTO plato.Output SELECT key FROM plato.Input
5686+
)sql");
5687+
UNIT_ASSERT(!res.IsOk());
5688+
UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:2:8: Error: UPSERT INTO is not supported for yt tables\n");
5689+
}
5690+
56895691
Y_UNIT_TEST(UpdateMapReduce) {
56905692
NYql::TAstParseResult res = SqlToYql("UPDATE plato.Output SET value = value + 1 WHERE key < 1");
56915693
UNIT_ASSERT(!res.Root);

yt/yql/providers/yt/gateway/native/yql_yt_native.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2565,7 +2565,7 @@ class TYtNativeGateway : public IYtGateway {
25652565
}
25662566

25672567
auto ytDst = TRichYPath(dstPath);
2568-
if ((EYtWriteMode::Append == mode && !appendToSorted) || EYtWriteMode::Upsert == mode) {
2568+
if ((EYtWriteMode::Append == mode && !appendToSorted) || EYtWriteMode::Replace == mode) {
25692569
ytDst.Append(true);
25702570
} else if (!dstIsDynamic) {
25712571
NYT::TNode fullSpecYson;

yt/yql/providers/yt/provider/yql_yt_datasink_type_ann.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,9 @@ class TYtDataSinkTypeAnnotationTransformer : public TVisitorTransformerBase {
472472
return TStatus::Error;
473473
}
474474

475-
if (mode != EYtWriteMode::Upsert && mode != EYtWriteMode::Renew) {
475+
if (mode != EYtWriteMode::Replace && mode != EYtWriteMode::Renew) {
476476
ctx.AddError(TIssue(pos, TStringBuilder() <<
477-
"Modification of dynamic table " << outTableInfo.Name.Quote() << " is supported only by UPSERT or INSERT WITH TRUNCATE"));
477+
"Modification of dynamic table " << outTableInfo.Name.Quote() << " is supported only by REPLACE or INSERT WITH TRUNCATE"));
478478
return TStatus::Error;
479479
}
480480

@@ -500,20 +500,20 @@ class TYtDataSinkTypeAnnotationTransformer : public TVisitorTransformerBase {
500500
}
501501
}
502502
}
503-
if (mode == EYtWriteMode::Upsert && !notFlowDynamic) {
503+
if (mode == EYtWriteMode::Replace && !notFlowDynamic) {
504504
ctx.AddError(TIssue(pos, TStringBuilder() <<
505505
"Modification of static table " << outTableInfo.Name.Quote() << " is supported only by INSERT"));
506506
return TStatus::Error;
507507
}
508508

509509
bool insertWithTruncateIntoDynamicTable = (mode == EYtWriteMode::Renew && notFlowDynamic);
510510
bool replaceMeta = !meta->DoesExist || (mode != EYtWriteMode::Append
511-
&& mode != EYtWriteMode::Upsert
511+
&& mode != EYtWriteMode::Replace
512512
&& !insertWithTruncateIntoDynamicTable
513513
&& mode != EYtWriteMode::RenewKeepMeta);
514514
bool checkLayout = meta->DoesExist && (mode == EYtWriteMode::Append
515515
|| mode == EYtWriteMode::RenewKeepMeta
516-
|| mode == EYtWriteMode::Upsert
516+
|| mode == EYtWriteMode::Replace
517517
|| insertWithTruncateIntoDynamicTable
518518
|| description.IsReplaced);
519519

yt/yql/providers/yt/provider/yql_yt_datasource.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ class TYtDataSource : public TDataProviderBase {
515515
TStringBuf intent;
516516
if (tableDesc.Intents & TYtTableIntent::Drop) {
517517
intent = "drop";
518-
} else if (tableDesc.Intents & (TYtTableIntent::Override | TYtTableIntent::Append | TYtTableIntent::Upsert)) {
518+
} else if (tableDesc.Intents & (TYtTableIntent::Override | TYtTableIntent::Append | TYtTableIntent::Replace)) {
519519
intent = "modify";
520520
} else if (tableDesc.Intents & TYtTableIntent::Flush) {
521521
intent = "flush";

yt/yql/providers/yt/provider/yql_yt_intent_determination.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ class TYtIntentDeterminationTransformer : public TVisitorTransformerBase {
112112
case EYtWriteMode::Flush:
113113
tableDesc.Intents |= TYtTableIntent::Flush;
114114
break;
115-
case EYtWriteMode::Upsert:
116-
tableDesc.Intents |= TYtTableIntent::Upsert;
115+
case EYtWriteMode::Replace:
116+
tableDesc.Intents |= TYtTableIntent::Replace;
117117
break;
118118
case EYtWriteMode::Create:
119119
tableDesc.Intents |= TYtTableIntent::Create;
@@ -277,8 +277,8 @@ class TYtIntentDeterminationTransformer : public TVisitorTransformerBase {
277277
case EYtWriteMode::Flush:
278278
tableDesc.Intents |= TYtTableIntent::Flush;
279279
break;
280-
case EYtWriteMode::Upsert:
281-
tableDesc.Intents |= TYtTableIntent::Upsert;
280+
case EYtWriteMode::Replace:
281+
tableDesc.Intents |= TYtTableIntent::Replace;
282282
break;
283283
default:
284284
ctx.AddError(TIssue(ctx.GetPosition(mode->Child(1)->Pos()), TStringBuilder() << "Unsupported "
@@ -341,8 +341,8 @@ class TYtIntentDeterminationTransformer : public TVisitorTransformerBase {
341341
case EYtWriteMode::Flush:
342342
tableDesc.Intents |= TYtTableIntent::Flush;
343343
break;
344-
case EYtWriteMode::Upsert:
345-
tableDesc.Intents |= TYtTableIntent::Upsert;
344+
case EYtWriteMode::Replace:
345+
tableDesc.Intents |= TYtTableIntent::Replace;
346346
break;
347347
default:
348348
ctx.AddError(TIssue(ctx.GetPosition(mode->Child(1)->Pos()), TStringBuilder() << "Unsupported "

yt/yql/providers/yt/provider/yql_yt_op_settings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ enum class EYtWriteMode: ui32 {
2525
Create /* "create" */,
2626
CreateIfNotExists /* "create_if_not_exists" */,
2727
Alter /* "alter" */,
28-
Upsert /* "upsert" */,
28+
Replace /* "replace" */,
2929
};
3030

3131
///////////////////////////////////////////////////////////////////////////////////////////////

yt/yql/providers/yt/provider/yql_yt_table_desc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ enum class TYtTableIntent: ui32 {
2828
Create = 1 << 4,
2929
Drop = 1 << 5,
3030
Flush = 1 << 6, // Untransactional write
31-
Upsert = 1 << 7,
31+
Replace = 1 << 7,
3232
};
3333

3434
Y_DECLARE_FLAGS(TYtTableIntents, TYtTableIntent);
@@ -39,11 +39,11 @@ inline bool HasReadIntents(TYtTableIntents intents) {
3939
}
4040

4141
inline bool HasModifyIntents(TYtTableIntents intents) {
42-
return intents & (TYtTableIntent::Override | TYtTableIntent::Append | TYtTableIntent::Drop | TYtTableIntent::Flush | TYtTableIntent::Create | TYtTableIntent::Upsert);
42+
return intents & (TYtTableIntent::Override | TYtTableIntent::Append | TYtTableIntent::Drop | TYtTableIntent::Flush | TYtTableIntent::Create | TYtTableIntent::Replace);
4343
}
4444

4545
inline bool HasExclusiveModifyIntents(TYtTableIntents intents) {
46-
return intents & (TYtTableIntent::Override | TYtTableIntent::Drop | TYtTableIntent::Flush | TYtTableIntent::Create | TYtTableIntent::Upsert);
46+
return intents & (TYtTableIntent::Override | TYtTableIntent::Drop | TYtTableIntent::Flush | TYtTableIntent::Create | TYtTableIntent::Replace);
4747
}
4848

4949
struct TYtViewDescription {

yt/yql/tests/sql/suites/insert_dynamic/insert_simple_fail.yql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* kikimr can not */
33
/* dqfile can not - missing langver support */
44
/* hybridfile can not - missing langver support */
5-
/* custom error:Modification of dynamic table "Output" is supported only by UPSERT or INSERT WITH TRUNCATE*/
5+
/* custom error: Modification of dynamic table "Output" is supported only by REPLACE or INSERT WITH TRUNCATE*/
66
use plato;
77

88
insert into Output

0 commit comments

Comments
 (0)