Skip to content

add external data source public API for description #14438

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
merged 2 commits into from
Feb 12, 2025

Conversation

jepett0
Copy link
Collaborator

@jepett0 jepett0 commented Feb 11, 2025

Add public API to describe external data sources and external tables.

Changelog entry

Changelog category

  • Not for changelog (changelog entry is not required)

Additional information

This comment was marked as outdated.

This comment was marked as outdated.

Ydb.Scheme.Entry self = 1;
optional string source_type = 2;
optional string location = 3;
optional string installation = 4;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Installation сейчас не используется, предлагаю когда имплементация появится, то добавить это поле

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

убрал

optional string data_source_path = 3;
optional string location = 4;
repeated ColumnMeta columns = 5;
optional bytes content = 6;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Content лучше развернуть в какой нибудь json/map<string, string> или же any с конкретными protobuf

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Развернул в map<string, string>.

Для полноты:

  • content - это NKikimrExternalSources::TGeneral, что видно здесь
  • в TGeneral помимо map<string, string> лежит ещё и location, но он был добавлен для валидации wildcard'ов, возможно, его и не нужно в description'е отдавать (тем более, в description external table уже есть location (см. поле номер 4)) @dorooleg, @GrigoriyPA

optional string source_type = 2;
optional string location = 3;
optional string installation = 4;
optional ExternalAuthorization authorization = 5;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Возможно authorization стоит развернуть и переместить в properties. Между этими именами не будет пересечений это гарантируется на уровне ddl сейчас

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Развернул Authorization в общий map<string, string> properties. Кажется, такое описание лучше ложится на:

  1. YQL для создания external data source. Смотри доку, там, по сути, CREATE EXTERNAL DATA SOURCE и куча структурно не связанных друг с другом параметров в WITH блоке. Такая независимость может быть удобна и предусмотрена by design (@dorooleg ?), чтобы легче было добавлять новые внешние источники данных.
  2. внутреннее представление этих параметров перед разворачиванием их в TModifyScheme (парсер сложил всё, что было в WITH блоке в map of features и мы оттуда достаём по имени параметр за параметром)

Иначе говоря, для создания external data source через публичный API (на данных момент это исключительно YQL) нужно собрать такую вот map of features. Поэтому естественно здесь, в describe, отдавать именно её.

Дополнительное усложнение в виде выделения ExternalAuthorization кажется избыточным, потому что такой структуры нет в CREATE EXTERNAL DATA SOURCE (она есть только на уровне приватных протобуфов SchemeShard'а), пользователь о ней не знает и в документации авторизация никак не выделена среди остальных свойств external data source

@jepett0 jepett0 requested a review from uzhastik February 11, 2025 12:58
}

message ExternalDataSourceProperties {
map<string, string> properties = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему это упаковано в отдельное сообщение?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Когда это было на уровне ModifyScheme SS, то была идея это сделать отдельным protobuf чтобы можно было какие-то типизированные настройки добавлять. Но пока что не пригодилось)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Выложил на верхний уровень DescribeExternalDataSourceResult'а и объединил с ExternalAuthorization, которые тоже развернул в map<string, string>. Подробнее в этом комменте

message None {
}

message Basic {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У нас это нигде явно не зафиксировано, но мы называем такую аутентификацию "статической": https://ydb.tech/docs/ru/recipes/ydb-sdk/auth-static

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Похоже мы разъехались в этом месте, тут уже упоминается как basic https://ydb.tech/docs/ru/concepts/federated_query/clickhouse :(

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Названия в данном месте не обязаны совпадать. Это различия между кредами к ydb и кредами к внешней системе. Статические креды-это просто некий класс кредов, можете в инете почитать

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Засунул авторизацию в общее поле map<string, string> properties. Теперь уже не важно, Static или Basic. Подробнее в этом комменте

message DescribeExternalDataSourceResult {
// Description of a generic scheme object.
Ydb.Scheme.Entry self = 1;
optional string source_type = 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А какими могут быть значения этого поля? Это S3/PostgreSQL/MySQL/... ?

Copy link
Collaborator Author

@jepett0 jepett0 Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Судя по доке:

В качестве источников данных можно использовать:

Но в коде main на данный момент написано следующее (этот код относится к External Table, смотри следующий коммент):

bool ValidateSourceType(const TString& sourceType, TString& errStr) {
    // Only object storage supported today
    if (sourceType != "ObjectStorage") {
        errStr = "Only ObjectStorage source type supported but got " + sourceType;
        return false;
    }
    return true;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ага, кажется, я понимаю - этот код не совсем оттуда. Этот валидатор относится к CREATE EXTERNAL TABLE, и в этой команде действительно единственный поддерживаемый источник - это S3. А вот в CREATE EXTERNAL DATA SOURCE поддерживаемых источников гораздо больше.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да, сорри, нашёл валидацию external data source. Тут список source type побольше, но полного я не нашёл (тут разобраны только некоторые опции):

 bool DataSourceMustHaveDataBaseName(const TProtoStringType& sourceType) const {
    return IsIn({"Greenplum", "PostgreSQL", "MySQL", "MsSQLServer", "ClickHouse"}, sourceType);
}

Copy link

github-actions bot commented Feb 12, 2025

2025-02-12 07:40:54 UTC Pre-commit check linux-x86_64-release-asan for 7c472ce has started.
2025-02-12 07:41:08 UTC Artifacts will be uploaded here
2025-02-12 07:44:23 UTC ya make is running...
🟡 2025-02-12 09:22:31 UTC Some tests failed, follow the links below. This fail is not in blocking policy yet Going to retry failed tests...

Test history | Ya make output | Test bloat

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
13833 13717 0 66 11 39

2025-02-12 09:23:56 UTC ya make is running... (failed tests rerun, try 2)
🟢 2025-02-12 09:35:59 UTC Tests successful.

Test history | Ya make output | Test bloat | Test bloat

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
160 (only retried tests) 122 0 0 3 35

🟢 2025-02-12 09:36:06 UTC Build successful.
🟡 2025-02-12 09:36:33 UTC ydbd size 3.6 GiB changed* by +698.5 KiB, which is >= 100.0 KiB vs main: Warning

ydbd size dash main: cdbb0bc merge: 7c472ce diff diff %
ydbd size 3 876 203 824 Bytes 3 876 919 104 Bytes +698.5 KiB +0.018%
ydbd stripped size 1 357 356 976 Bytes 1 357 633 776 Bytes +270.3 KiB +0.020%

*please be aware that the difference is based on comparing your commit and the last completed build from the post-commit, check comparation

@jepett0 jepett0 marked this pull request as ready for review February 12, 2025 08:43
@dorooleg
Copy link
Collaborator

lgtm

@jepett0 jepett0 linked an issue Feb 12, 2025 that may be closed by this pull request
Copy link

github-actions bot commented Feb 12, 2025

2025-02-12 16:36:04 UTC Pre-commit check linux-x86_64-relwithdebinfo for 7c472ce has started.
2025-02-12 16:37:47 UTC Artifacts will be uploaded here
2025-02-12 16:41:09 UTC ya make is running...
🟡 2025-02-12 18:12:11 UTC Some tests failed, follow the links below. Going to retry failed tests...

Test history | Ya make output | Test bloat

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
28071 25480 0 3 2449 139

2025-02-12 18:17:30 UTC ya make is running... (failed tests rerun, try 2)
🟢 2025-02-12 18:29:43 UTC Tests successful.

Test history | Ya make output | Test bloat | Test bloat

TESTS PASSED ERRORS FAILED SKIPPED MUTED?
217 (only retried tests) 90 0 0 0 127

🟢 2025-02-12 18:29:51 UTC Build successful.
🟡 2025-02-12 18:30:11 UTC ydbd size 2.1 GiB changed* by +380.8 KiB, which is >= 100.0 KiB vs main: Warning

ydbd size dash main: cdbb0bc merge: 7c472ce diff diff %
ydbd size 2 228 945 224 Bytes 2 229 335 192 Bytes +380.8 KiB +0.017%
ydbd stripped size 473 261 656 Bytes 473 331 512 Bytes +68.2 KiB +0.015%

*please be aware that the difference is based on comparing your commit and the last completed build from the post-commit, check comparation

@jepett0 jepett0 merged commit 4fee494 into ydb-platform:main Feb 12, 2025
12 checks passed
lberserq pushed a commit to lberserq/ydb that referenced this pull request Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

external data sources: describe
5 participants