|
1 | 1 | #include "util/charset/utf8.h"
|
2 | 2 | #include "utils.h"
|
3 | 3 | #include "ydb/public/api/protos/ydb_value.pb.h"
|
| 4 | +#include <memory> |
4 | 5 | #include <ydb/library/yql/sql/settings/partitioning.h>
|
5 | 6 | #include <ydb/library/yql/parser/pg_wrapper/interface/config.h>
|
6 | 7 | #include <ydb/library/yql/parser/pg_wrapper/interface/parser.h>
|
7 | 8 | #include <ydb/library/yql/parser/pg_wrapper/interface/utils.h>
|
8 | 9 | #include <ydb/library/yql/parser/pg_wrapper/interface/raw_parser.h>
|
9 | 10 | #include <ydb/library/yql/parser/pg_wrapper/postgresql/src/backend/catalog/pg_type_d.h>
|
| 11 | +//#include <ydb/library/yql/parser/pg_wrapper/postgresql/src/include/commands/defrem.h> |
10 | 12 | #include <ydb/library/yql/parser/pg_catalog/catalog.h>
|
11 | 13 | #include <ydb/library/yql/providers/common/provider/yql_provider_names.h>
|
12 | 14 | #include <ydb/library/yql/core/issue/yql_issue.h>
|
@@ -2657,82 +2659,79 @@ class TConverter : public IPGParseEvents {
|
2657 | 2659 |
|
2658 | 2660 | std::vector<TAstNode*> options;
|
2659 | 2661 |
|
2660 |
| - if (value->accessMethod) { |
2661 |
| - AddError("USING not supported"); |
2662 |
| - return nullptr; |
2663 |
| - } |
2664 |
| - |
2665 |
| - if (value->if_not_exists) { |
2666 |
| - TString mode = (ctx.ifNotExists) ? "create_if_not_exists" : "create"; |
2667 |
| - options.push_back(QL(QA("mode"), QA(mode))); |
2668 |
| - } |
| 2662 | + TString mode = (value->if_not_exists) ? "create_if_not_exists" : "create"; |
| 2663 | + options.push_back(QL(QA("mode"), QA(mode))); |
2669 | 2664 |
|
2670 |
| - auto [sink, key] = ParseWriteRangeVar(value->sequence, true); |
| 2665 | + auto [sink, key] = ParseQualifiedPgObjectName( |
| 2666 | + value->sequence->catalogname, |
| 2667 | + value->sequence->schemaname, |
| 2668 | + value->sequence->relname, |
| 2669 | + "pgSequence" |
| 2670 | + ); |
2671 | 2671 |
|
2672 | 2672 | if (!sink || !key) {
|
2673 | 2673 | return nullptr;
|
2674 | 2674 | }
|
2675 | 2675 |
|
| 2676 | + const auto relPersistence = static_cast<NPg::ERelPersistence>(value->sequence->relpersistence); |
| 2677 | + switch (relPersistence) { |
| 2678 | + case NPg::ERelPersistence::Temp: |
| 2679 | + options.push_back(QL(QA("temporary"))); |
| 2680 | + break; |
| 2681 | + case NPg::ERelPersistence::Unlogged: |
| 2682 | + AddError("UNLOGGED sequence not supported"); |
| 2683 | + return nullptr; |
| 2684 | + break; |
| 2685 | + case NPg::ERelPersistence::Permanent: |
| 2686 | + break; |
| 2687 | + } |
| 2688 | + |
2676 | 2689 | for (int i = 0; i < ListLength(value->options); ++i) {
|
2677 | 2690 | auto rawNode = ListNodeNth(value->options, i);
|
2678 | 2691 |
|
2679 | 2692 | switch (NodeTag(rawNode)) {
|
2680 |
| - case T_DefElem: |
2681 |
| - auto defElem = CAST_NODE(ColumnDef, rawNode); |
2682 |
| - return nullptr; |
| 2693 | + case T_DefElem: { |
| 2694 | + const auto* defElem = CAST_NODE(DefElem, rawNode); |
| 2695 | + TStringBuf nameElem = defElem->defname; |
| 2696 | + if (defElem->arg) { |
| 2697 | + switch (NodeTag(defElem->arg)) |
| 2698 | + { |
| 2699 | + case T_Integer: |
| 2700 | + options.emplace_back(QL(QA(nameElem), QA(ToString(intVal(defElem->arg))))); |
| 2701 | + break; |
| 2702 | + case T_Float: |
| 2703 | + options.emplace_back(QL(QA(nameElem), QA(strVal(defElem->arg)))); |
| 2704 | + break; |
| 2705 | + case T_TypeName: { |
| 2706 | + const auto* typeName = reinterpret_cast<PG_TypeName*>(defElem->arg); |
| 2707 | + options.emplace_back(QL(QA(nameElem), |
| 2708 | + QA(StrVal(ListNodeNth(typeName->names, ListLength(typeName->names) - 1))))); |
| 2709 | + break; |
| 2710 | + } |
| 2711 | + default: |
| 2712 | + AddError("storage parameters for index is not supported yet:" + TString(nameElem)); |
| 2713 | + NodeNotImplemented(defElem->arg); |
| 2714 | + return nullptr; |
| 2715 | + } |
2683 | 2716 | }
|
2684 | 2717 | break;
|
2685 |
| - |
| 2718 | + } |
2686 | 2719 | default:
|
2687 |
| - NodeNotImplemented(value, rawNode); |
| 2720 | + NodeNotImplemented(rawNode); |
2688 | 2721 | return nullptr;
|
2689 | 2722 | }
|
2690 | 2723 | }
|
2691 | 2724 |
|
2692 |
| - TString mode = (ctx.ifNotExists) ? "create_if_not_exists" : "create"; |
2693 |
| - options.push_back(QL(QA("mode"), QA(mode))); |
2694 |
| - options.push_back(QL(QA("columns"), BuildColumnsOptions(ctx))); |
2695 |
| - if (!ctx.PrimaryKey.empty()) { |
2696 |
| - options.push_back(QL(QA("primarykey"), QVL(ctx.PrimaryKey.data(), ctx.PrimaryKey.size()))); |
2697 |
| - } |
2698 |
| - for (auto& uniq : ctx.UniqConstr) { |
2699 |
| - auto columns = QVL(uniq.data(), uniq.size()); |
2700 |
| - options.push_back(QL(QA("index"), QL( |
2701 |
| - QL(QA("indexName")), |
2702 |
| - QL(QA("indexType"), QA("syncGlobalUnique")), |
2703 |
| - QL(QA("dataColumns"), QL()), |
2704 |
| - QL(QA("indexColumns"), columns)))); |
2705 |
| - } |
2706 |
| - if (ctx.isTemporary) { |
2707 |
| - options.push_back(QL(QA("temporary"))); |
| 2725 | + if (value->for_identity) { |
| 2726 | + options.push_back(QL(QA("for_identity"))); |
2708 | 2727 | }
|
2709 | 2728 |
|
2710 |
| - for (int i = 0; i < ListLength(value->tableElts); ++i) { |
2711 |
| - auto rawNode = ListNodeNth(value->tableElts, i); |
2712 |
| - |
2713 |
| - switch (NodeTag(rawNode)) { |
2714 |
| - case T_ColumnDef: |
2715 |
| - if (!AddColumn(ctx, CAST_NODE(ColumnDef, rawNode))) { |
2716 |
| - return nullptr; |
2717 |
| - } |
2718 |
| - break; |
2719 |
| - |
2720 |
| - case T_Constraint: |
2721 |
| - if (!AddConstraint(ctx, CAST_NODE(Constraint, rawNode))) { |
2722 |
| - return nullptr; |
2723 |
| - } |
2724 |
| - break; |
2725 |
| - |
2726 |
| - default: |
2727 |
| - NodeNotImplemented(value, rawNode); |
2728 |
| - return nullptr; |
2729 |
| - } |
2730 |
| - } |
| 2729 | + options.push_back(QL(QA("owner_id"), QA(ToString(value->ownerId)))); |
2731 | 2730 |
|
2732 | 2731 | State.Statements.push_back(
|
2733 | 2732 | L(A("let"), A("world"),
|
2734 | 2733 | L(A("Write!"), A("world"), sink, key, L(A("Void")),
|
2735 |
| - BuildCreateTableOptions(ctx)))); |
| 2734 | + QVL(options.data(), options.size())))); |
2736 | 2735 |
|
2737 | 2736 | return State.Statements.back();
|
2738 | 2737 | }
|
|
0 commit comments