@intentius/chant-lexicon-sql 0.124.46 → 0.124.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/change-set.d.ts +1 -1
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +2 -1
- package/dist/clickhouse/apply/statements.d.ts +9 -0
- package/dist/clickhouse/apply/statements.d.ts.map +1 -1
- package/dist/clickhouse/apply/statements.js +24 -0
- package/dist/clickhouse/import/live-export.d.ts +7 -3
- package/dist/clickhouse/import/live-export.d.ts.map +1 -1
- package/dist/clickhouse/import/live-export.js +21 -5
- package/dist/clickhouse/live/named-collections.d.ts +27 -0
- package/dist/clickhouse/live/named-collections.d.ts.map +1 -0
- package/dist/clickhouse/live/named-collections.js +53 -0
- package/dist/clickhouse/live/undeclarable.d.ts +15 -3
- package/dist/clickhouse/live/undeclarable.d.ts.map +1 -1
- package/dist/clickhouse/live/undeclarable.js +18 -4
- package/dist/clickhouse/named-collections.d.ts +83 -0
- package/dist/clickhouse/named-collections.d.ts.map +1 -0
- package/dist/clickhouse/named-collections.js +203 -0
- package/dist/clickhouse/parser.d.ts.map +1 -1
- package/dist/clickhouse/parser.js +1 -1
- package/dist/clickhouse/plan/commands.d.ts +2 -1
- package/dist/clickhouse/plan/commands.d.ts.map +1 -1
- package/dist/clickhouse/plan/commands.js +17 -2
- package/dist/clickhouse/plan/diff.d.ts +15 -0
- package/dist/clickhouse/plan/diff.d.ts.map +1 -1
- package/dist/clickhouse/plan/diff.js +43 -1
- package/dist/clickhouse/plan/disruption.d.ts.map +1 -1
- package/dist/clickhouse/plan/disruption.js +5 -0
- package/dist/clickhouse/plan/rebuild-handoff.d.ts.map +1 -1
- package/dist/clickhouse/plan/rebuild-handoff.js +4 -0
- package/dist/clickhouse/plan/report.d.ts.map +1 -1
- package/dist/clickhouse/plan/report.js +6 -1
- package/dist/clickhouse/plan/rules.d.ts +5 -1
- package/dist/clickhouse/plan/rules.d.ts.map +1 -1
- package/dist/clickhouse/plan/rules.js +7 -3
- package/dist/clickhouse/plan/statements.d.ts +29 -0
- package/dist/clickhouse/plan/statements.d.ts.map +1 -0
- package/dist/clickhouse/plan/statements.js +334 -0
- package/dist/clickhouse/plan/stream.d.ts +40 -0
- package/dist/clickhouse/plan/stream.d.ts.map +1 -0
- package/dist/clickhouse/plan/stream.js +107 -0
- package/dist/clickhouse/rebuild/observe.d.ts +3 -1
- package/dist/clickhouse/rebuild/observe.d.ts.map +1 -1
- package/dist/clickhouse/rebuild/observe.js +14 -1
- package/dist/clickhouse/review-catalog.d.ts +213 -0
- package/dist/clickhouse/review-catalog.d.ts.map +1 -0
- package/dist/clickhouse/review-catalog.js +330 -0
- package/dist/codegen/classifier-page.d.ts.map +1 -1
- package/dist/codegen/classifier-page.js +44 -4
- package/dist/codegen/clickhouse-module.d.ts.map +1 -1
- package/dist/codegen/clickhouse-module.js +3 -0
- package/dist/codegen/coverage-page.d.ts.map +1 -1
- package/dist/codegen/coverage-page.js +5 -3
- package/dist/codegen/docs.js +1 -1
- package/dist/codegen/postgres-classifier-page.js +2 -2
- package/dist/codegen/registry.d.ts.map +1 -1
- package/dist/codegen/registry.js +10 -0
- package/dist/composites/catalog.d.ts.map +1 -1
- package/dist/composites/catalog.js +100 -0
- package/dist/composites/clickhouse.d.ts +2 -0
- package/dist/composites/clickhouse.d.ts.map +1 -1
- package/dist/composites/clickhouse.js +2 -0
- package/dist/composites/otel-tables.d.ts +100 -0
- package/dist/composites/otel-tables.d.ts.map +1 -0
- package/dist/composites/otel-tables.js +282 -0
- package/dist/composites/stream-ingest.d.ts +63 -0
- package/dist/composites/stream-ingest.d.ts.map +1 -0
- package/dist/composites/stream-ingest.js +39 -0
- package/dist/core/statement-class.d.ts +55 -0
- package/dist/core/statement-class.d.ts.map +1 -0
- package/dist/core/statement-class.js +43 -0
- package/dist/coverage/clickhouse.json +1 -1
- package/dist/coverage/postgres.json +12 -12
- package/dist/coverage.d.ts +16 -6
- package/dist/coverage.d.ts.map +1 -1
- package/dist/coverage.js +10 -5
- package/dist/drizzle-command.d.ts +17 -0
- package/dist/drizzle-command.d.ts.map +1 -0
- package/dist/drizzle-command.js +91 -0
- package/dist/drizzle.d.ts +70 -0
- package/dist/drizzle.d.ts.map +1 -0
- package/dist/drizzle.js +689 -0
- package/dist/files/clickhouse.d.ts.map +1 -1
- package/dist/files/clickhouse.js +8 -1
- package/dist/files/common.d.ts +13 -0
- package/dist/files/common.d.ts.map +1 -1
- package/dist/files/common.js +5 -0
- package/dist/files/postgres.d.ts.map +1 -1
- package/dist/files/postgres.js +35 -3
- package/dist/generated/clickhouse.d.ts +2 -0
- package/dist/generated/clickhouse.d.ts.map +1 -1
- package/dist/generated/clickhouse.js +2 -0
- package/dist/import-parser.d.ts +21 -1
- package/dist/import-parser.d.ts.map +1 -1
- package/dist/import-parser.js +79 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/integrity.json +7 -6
- package/dist/lint/post-synth/audit-entries.d.ts.map +1 -1
- package/dist/lint/post-synth/audit-entries.js +1 -0
- package/dist/lint/post-synth/index.d.ts.map +1 -1
- package/dist/lint/post-synth/index.js +2 -0
- package/dist/lint/post-synth/postgres-names.d.ts.map +1 -1
- package/dist/lint/post-synth/postgres-names.js +3 -0
- package/dist/lint/post-synth/sqlch128.d.ts +18 -0
- package/dist/lint/post-synth/sqlch128.d.ts.map +1 -0
- package/dist/lint/post-synth/sqlch128.js +222 -0
- package/dist/lint/rules/postgres-templates.js +2 -2
- package/dist/lsp/postgres-template.d.ts.map +1 -1
- package/dist/lsp/postgres-template.js +21 -0
- package/dist/manifest.json +1 -1
- package/dist/mcp/postgres.js +1 -1
- package/dist/meta.json +50 -0
- package/dist/migrate/from-postgres/detect.d.ts +4 -0
- package/dist/migrate/from-postgres/detect.d.ts.map +1 -0
- package/dist/migrate/from-postgres/detect.js +7 -0
- package/dist/migrate/from-postgres/emit.d.ts +26 -0
- package/dist/migrate/from-postgres/emit.d.ts.map +1 -0
- package/dist/migrate/from-postgres/emit.js +86 -0
- package/dist/migrate/from-postgres/index.d.ts +51 -0
- package/dist/migrate/from-postgres/index.d.ts.map +1 -0
- package/dist/migrate/from-postgres/index.js +115 -0
- package/dist/migrate/from-postgres/translate.d.ts +73 -0
- package/dist/migrate/from-postgres/translate.d.ts.map +1 -0
- package/dist/migrate/from-postgres/translate.js +261 -0
- package/dist/migrate/from-postgres/types.d.ts +51 -0
- package/dist/migrate/from-postgres/types.d.ts.map +1 -0
- package/dist/migrate/from-postgres/types.js +211 -0
- package/dist/migration-classify.d.ts +23 -0
- package/dist/migration-classify.d.ts.map +1 -0
- package/dist/migration-classify.js +44 -0
- package/dist/migration-replay.d.ts +73 -0
- package/dist/migration-replay.d.ts.map +1 -0
- package/dist/migration-replay.js +294 -0
- package/dist/okf/index.md +11 -0
- package/dist/okf/rules/SQLCH128.md +11 -0
- package/dist/okf/types/PostgresForeignDataWrapper.md +9 -0
- package/dist/okf/types/PostgresForeignServer.md +9 -0
- package/dist/okf/types/PostgresForeignTable.md +9 -0
- package/dist/okf/types/PostgresOperator.md +9 -0
- package/dist/okf/types/PostgresOperatorClass.md +9 -0
- package/dist/okf/types/PostgresOperatorFamily.md +9 -0
- package/dist/okf/types/PostgresPublication.md +9 -0
- package/dist/okf/types/PostgresStatistics.md +9 -0
- package/dist/okf/types/PostgresTextSearchConfiguration.md +9 -0
- package/dist/okf/types/PostgresTextSearchDictionary.md +9 -0
- package/dist/op/activities/postgres-migration.d.ts.map +1 -1
- package/dist/op/activities/postgres-migration.js +4 -0
- package/dist/op/activity-contracts.d.ts +20 -0
- package/dist/op/activity-contracts.d.ts.map +1 -1
- package/dist/op/activity-contracts.js +2 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +49 -2
- package/dist/postgres/access/acl.js +1 -1
- package/dist/postgres/access/import.js +1 -1
- package/dist/postgres/apply/apply.js +13 -1
- package/dist/postgres/apply/statements.d.ts.map +1 -1
- package/dist/postgres/apply/statements.js +243 -4
- package/dist/postgres/constraint-names.d.ts +30 -0
- package/dist/postgres/constraint-names.d.ts.map +1 -0
- package/dist/postgres/constraint-names.js +72 -0
- package/dist/postgres/entities.d.ts +229 -2
- package/dist/postgres/entities.d.ts.map +1 -1
- package/dist/postgres/entities.js +326 -5
- package/dist/postgres/entity-types.d.ts +10 -0
- package/dist/postgres/entity-types.d.ts.map +1 -1
- package/dist/postgres/entity-types.js +10 -0
- package/dist/postgres/import/generator.d.ts.map +1 -1
- package/dist/postgres/import/generator.js +65 -2
- package/dist/postgres/import/live-export.d.ts.map +1 -1
- package/dist/postgres/import/live-export.js +2 -0
- package/dist/postgres/live/catalog-kinds.d.ts +20 -0
- package/dist/postgres/live/catalog-kinds.d.ts.map +1 -1
- package/dist/postgres/live/catalog-kinds.js +452 -0
- package/dist/postgres/live/catalog.d.ts +2 -0
- package/dist/postgres/live/catalog.d.ts.map +1 -1
- package/dist/postgres/live/catalog.js +3 -1
- package/dist/postgres/live/describe-resources.d.ts.map +1 -1
- package/dist/postgres/live/describe-resources.js +12 -2
- package/dist/postgres/migrate/backfill.d.ts +2 -0
- package/dist/postgres/migrate/backfill.d.ts.map +1 -1
- package/dist/postgres/migrate/backfill.js +7 -1
- package/dist/postgres/migrate/carry.d.ts +45 -1
- package/dist/postgres/migrate/carry.d.ts.map +1 -1
- package/dist/postgres/migrate/carry.js +72 -8
- package/dist/postgres/migrate/observe.d.ts +28 -4
- package/dist/postgres/migrate/observe.d.ts.map +1 -1
- package/dist/postgres/migrate/observe.js +45 -13
- package/dist/postgres/migrate/op.d.ts +26 -1
- package/dist/postgres/migrate/op.d.ts.map +1 -1
- package/dist/postgres/migrate/op.js +3 -1
- package/dist/postgres/migrate/replication.d.ts +42 -0
- package/dist/postgres/migrate/replication.d.ts.map +1 -1
- package/dist/postgres/migrate/replication.js +53 -0
- package/dist/postgres/migrate/steps.d.ts +35 -2
- package/dist/postgres/migrate/steps.d.ts.map +1 -1
- package/dist/postgres/migrate/steps.js +158 -12
- package/dist/postgres/parser.d.ts +144 -1
- package/dist/postgres/parser.d.ts.map +1 -1
- package/dist/postgres/parser.js +370 -4
- package/dist/postgres/plan/deep.d.ts.map +1 -1
- package/dist/postgres/plan/deep.js +43 -4
- package/dist/postgres/plan/diff.d.ts.map +1 -1
- package/dist/postgres/plan/diff.js +154 -1
- package/dist/postgres/plan/normalize.d.ts +28 -2
- package/dist/postgres/plan/normalize.d.ts.map +1 -1
- package/dist/postgres/plan/normalize.js +260 -1
- package/dist/postgres/plan/rules.d.ts +4 -0
- package/dist/postgres/plan/rules.d.ts.map +1 -1
- package/dist/postgres/plan/rules.js +6 -2
- package/dist/postgres/plan/schema.js +1 -1
- package/dist/postgres/plan/statements.d.ts +26 -0
- package/dist/postgres/plan/statements.d.ts.map +1 -0
- package/dist/postgres/plan/statements.js +364 -0
- package/dist/postgres/secret-options.d.ts +10 -0
- package/dist/postgres/secret-options.d.ts.map +1 -0
- package/dist/postgres/secret-options.js +9 -0
- package/dist/postgres/testing/roundtrip-schema.d.ts +4 -2
- package/dist/postgres/testing/roundtrip-schema.d.ts.map +1 -1
- package/dist/postgres/testing/roundtrip-schema.js +24 -1
- package/dist/postgres.d.ts +1 -1
- package/dist/postgres.d.ts.map +1 -1
- package/dist/postgres.js +1 -1
- package/dist/rules/audit-entries.ts +1 -0
- package/dist/rules/postgres-names.ts +2 -0
- package/dist/rules/postgres-templates.ts +2 -2
- package/dist/rules/sqlch128.ts +230 -0
- package/dist/serializer.d.ts +5 -0
- package/dist/serializer.d.ts.map +1 -1
- package/dist/serializer.js +13 -2
- package/dist/sql-types-command.d.ts +13 -0
- package/dist/sql-types-command.d.ts.map +1 -1
- package/dist/sql-types-command.js +31 -16
- package/dist/sql-types.d.ts +22 -0
- package/dist/sql-types.d.ts.map +1 -1
- package/dist/sql-types.js +10 -6
- package/dist/sqlserver/lexer.d.ts +37 -0
- package/dist/sqlserver/lexer.d.ts.map +1 -0
- package/dist/sqlserver/lexer.js +254 -0
- package/dist/sqlserver/parse.d.ts +185 -0
- package/dist/sqlserver/parse.d.ts.map +1 -0
- package/dist/sqlserver/parse.js +767 -0
- package/dist/sqlserver/translate.d.ts +34 -0
- package/dist/sqlserver/translate.d.ts.map +1 -0
- package/dist/sqlserver/translate.js +495 -0
- package/dist/sqlserver/types.d.ts +44 -0
- package/dist/sqlserver/types.d.ts.map +1 -0
- package/dist/sqlserver/types.js +133 -0
- package/dist/sqlserver/validate.d.ts +31 -0
- package/dist/sqlserver/validate.d.ts.map +1 -0
- package/dist/sqlserver/validate.js +67 -0
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +10 -0
- package/package.json +2 -2
- package/src/change-set.ts +2 -1
- package/src/clickhouse/apply/statements.ts +25 -0
- package/src/clickhouse/import/live-export.ts +20 -5
- package/src/clickhouse/live/named-collections.e2e.test.ts +88 -0
- package/src/clickhouse/live/named-collections.ts +61 -0
- package/src/clickhouse/live/undeclarable.e2e.test.ts +5 -3
- package/src/clickhouse/live/undeclarable.ts +20 -4
- package/src/clickhouse/named-collections.test.ts +187 -0
- package/src/clickhouse/named-collections.ts +224 -0
- package/src/clickhouse/parser.ts +2 -1
- package/src/clickhouse/plan/commands.ts +17 -2
- package/src/clickhouse/plan/diff.ts +57 -1
- package/src/clickhouse/plan/disruption.ts +5 -0
- package/src/clickhouse/plan/rebuild-handoff.ts +3 -0
- package/src/clickhouse/plan/report.ts +6 -1
- package/src/clickhouse/plan/rules.ts +14 -4
- package/src/clickhouse/plan/statements.test.ts +61 -0
- package/src/clickhouse/plan/statements.ts +306 -0
- package/src/clickhouse/plan/stream-s3queue.e2e.test.ts +148 -0
- package/src/clickhouse/plan/stream.test.ts +237 -0
- package/src/clickhouse/plan/stream.ts +111 -0
- package/src/clickhouse/rebuild/observe.ts +15 -1
- package/src/clickhouse/review-catalog.test.ts +181 -0
- package/src/clickhouse/review-catalog.ts +489 -0
- package/src/codegen/classifier-page.ts +44 -4
- package/src/codegen/clickhouse-module.ts +3 -0
- package/src/codegen/coverage-page.ts +5 -3
- package/src/codegen/docs.ts +1 -1
- package/src/codegen/postgres-classifier-page.ts +2 -2
- package/src/codegen/registry.ts +10 -0
- package/src/composites/catalog.test.ts +6 -1
- package/src/composites/catalog.ts +100 -0
- package/src/composites/clickhouse.ts +2 -0
- package/src/composites/composites.test.ts +1 -1
- package/src/composites/otel-tables.test.ts +118 -0
- package/src/composites/otel-tables.ts +339 -0
- package/src/composites/stream-ingest.test.ts +114 -0
- package/src/composites/stream-ingest.ts +82 -0
- package/src/core/statement-class.ts +88 -0
- package/src/core/undeclarable.test.ts +6 -5
- package/src/coverage/clickhouse.json +1 -1
- package/src/coverage/postgres.json +12 -12
- package/src/coverage.test.ts +27 -2
- package/src/coverage.ts +18 -7
- package/src/drizzle-command.ts +94 -0
- package/src/drizzle-kit.e2e.test.ts +89 -0
- package/src/drizzle-types.e2e.test.ts +67 -0
- package/src/drizzle.test.ts +358 -0
- package/src/drizzle.ts +742 -0
- package/src/files/clickhouse.ts +8 -1
- package/src/files/common.ts +14 -1
- package/src/files/postgres.ts +34 -3
- package/src/generated/clickhouse.ts +3 -0
- package/src/generated/lexicon-sql.json +50 -0
- package/src/import-parser.sqlserver.test.ts +92 -0
- package/src/import-parser.ts +79 -5
- package/src/index.ts +1 -1
- package/src/lint/post-synth/audit-entries.ts +1 -0
- package/src/lint/post-synth/index.ts +2 -0
- package/src/lint/post-synth/postgres-checks.test.ts +8 -1
- package/src/lint/post-synth/postgres-names.ts +2 -0
- package/src/lint/post-synth/sqlch128.test.ts +107 -0
- package/src/lint/post-synth/sqlch128.ts +230 -0
- package/src/lint/rules/postgres-templates.ts +2 -2
- package/src/lsp/postgres-template.ts +20 -0
- package/src/mcp/postgres.ts +1 -1
- package/src/migrate/from-postgres/cli.test.ts +165 -0
- package/src/migrate/from-postgres/detect.ts +7 -0
- package/src/migrate/from-postgres/emit.ts +96 -0
- package/src/migrate/from-postgres/example.test.ts +205 -0
- package/src/migrate/from-postgres/index.ts +122 -0
- package/src/migrate/from-postgres/translate.test.ts +242 -0
- package/src/migrate/from-postgres/translate.ts +359 -0
- package/src/migrate/from-postgres/types.test.ts +116 -0
- package/src/migrate/from-postgres/types.ts +236 -0
- package/src/migrate/from-postgres/validate.e2e.test.ts +44 -0
- package/src/migrate/from-postgres/workspace.e2e.test.ts +114 -0
- package/src/migration-classify.test.ts +150 -0
- package/src/migration-classify.ts +45 -0
- package/src/migration-replay.e2e.test.ts +155 -0
- package/src/migration-replay.test.ts +173 -0
- package/src/migration-replay.ts +289 -0
- package/src/op/__snapshots__/watch-pipeline.test.ts.snap +2 -2
- package/src/op/activities/postgres-migration.ts +4 -0
- package/src/op/activity-contracts.ts +2 -0
- package/src/op/watch-pipeline.test.ts +8 -1
- package/src/plugin.ts +51 -2
- package/src/postgres/access/acl.ts +1 -1
- package/src/postgres/access/import.ts +1 -1
- package/src/postgres/apply/apply.ts +14 -1
- package/src/postgres/apply/statements.ts +225 -4
- package/src/postgres/constraint-names.ts +71 -0
- package/src/postgres/database-kinds.test.ts +865 -0
- package/src/postgres/entities.ts +541 -5
- package/src/postgres/entity-types.ts +10 -0
- package/src/postgres/import/generator.ts +54 -2
- package/src/postgres/import/live-export.ts +1 -0
- package/src/postgres/live/catalog-kinds.ts +494 -0
- package/src/postgres/live/catalog.ts +6 -1
- package/src/postgres/live/database-kinds.e2e.test.ts +164 -0
- package/src/postgres/live/describe-resources.ts +13 -2
- package/src/postgres/live/undeclarable.e2e.test.ts +13 -6
- package/src/postgres/migrate/backfill.ts +13 -1
- package/src/postgres/migrate/carry.ts +103 -8
- package/src/postgres/migrate/followups.e2e.test.ts +218 -0
- package/src/postgres/migrate/followups.test.ts +199 -0
- package/src/postgres/migrate/kinds.e2e.test.ts +5 -5
- package/src/postgres/migrate/observe.ts +56 -15
- package/src/postgres/migrate/op.ts +28 -1
- package/src/postgres/migrate/partition.e2e.test.ts +129 -0
- package/src/postgres/migrate/partition.test.ts +206 -0
- package/src/postgres/migrate/replication.ts +66 -0
- package/src/postgres/migrate/steps.ts +157 -12
- package/src/postgres/migrate/subscriber.e2e.test.ts +141 -0
- package/src/postgres/migrate/subscriber.test.ts +59 -0
- package/src/postgres/parser.ts +455 -4
- package/src/postgres/plan/deep.ts +42 -4
- package/src/postgres/plan/diff.ts +137 -1
- package/src/postgres/plan/normalize.ts +277 -1
- package/src/postgres/plan/rules.ts +32 -4
- package/src/postgres/plan/schema.ts +1 -1
- package/src/postgres/plan/statements.test.ts +78 -0
- package/src/postgres/plan/statements.ts +299 -0
- package/src/postgres/secret-options.ts +10 -0
- package/src/postgres/testing/roundtrip-schema.ts +24 -1
- package/src/postgres.ts +33 -0
- package/src/serializer.ts +13 -2
- package/src/skills/chant-sql-postgres-migration.md +4 -3
- package/src/skills/chant-sql-postgres.md +11 -1
- package/src/skills/chant-sql.md +2 -1
- package/src/sql-files.test.ts +33 -0
- package/src/sql-types-command.ts +38 -16
- package/src/sql-types.ts +11 -6
- package/src/sqlserver/fixture.test.ts +186 -0
- package/src/sqlserver/import-cli.test.ts +61 -0
- package/src/sqlserver/lexer.ts +260 -0
- package/src/sqlserver/parse.ts +865 -0
- package/src/sqlserver/translate.test.ts +396 -0
- package/src/sqlserver/translate.ts +558 -0
- package/src/sqlserver/types.test.ts +102 -0
- package/src/sqlserver/types.ts +154 -0
- package/src/sqlserver/validate.e2e.test.ts +32 -0
- package/src/sqlserver/validate.test.ts +49 -0
- package/src/sqlserver/validate.ts +76 -0
- package/src/validate.ts +10 -0
- package/src/workspace-kinds.test.ts +11 -0
- package/workspace-kinds.json +100 -2
package/src/codegen/registry.ts
CHANGED
|
@@ -39,6 +39,16 @@ const KINDS: Record<string, string> = {
|
|
|
39
39
|
PostgresCollation: POSTGRES_ENTITY_TYPES.collation,
|
|
40
40
|
PostgresCast: POSTGRES_ENTITY_TYPES.cast,
|
|
41
41
|
PostgresEventTrigger: POSTGRES_ENTITY_TYPES.eventTrigger,
|
|
42
|
+
PostgresOperator: POSTGRES_ENTITY_TYPES.operator,
|
|
43
|
+
PostgresOperatorClass: POSTGRES_ENTITY_TYPES.operatorClass,
|
|
44
|
+
PostgresOperatorFamily: POSTGRES_ENTITY_TYPES.operatorFamily,
|
|
45
|
+
PostgresForeignTable: POSTGRES_ENTITY_TYPES.foreignTable,
|
|
46
|
+
PostgresTextSearchConfiguration: POSTGRES_ENTITY_TYPES.textSearchConfiguration,
|
|
47
|
+
PostgresTextSearchDictionary: POSTGRES_ENTITY_TYPES.textSearchDictionary,
|
|
48
|
+
PostgresStatistics: POSTGRES_ENTITY_TYPES.statistics,
|
|
49
|
+
PostgresForeignDataWrapper: POSTGRES_ENTITY_TYPES.foreignDataWrapper,
|
|
50
|
+
PostgresForeignServer: POSTGRES_ENTITY_TYPES.foreignServer,
|
|
51
|
+
PostgresPublication: POSTGRES_ENTITY_TYPES.publication,
|
|
42
52
|
PostgresExtension: POSTGRES_ENTITY_TYPES.extension,
|
|
43
53
|
PostgresFunction: POSTGRES_ENTITY_TYPES.function,
|
|
44
54
|
PostgresProcedure: POSTGRES_ENTITY_TYPES.procedure,
|
|
@@ -24,11 +24,13 @@ describe("the sql composite catalog", () => {
|
|
|
24
24
|
"CdcMirror",
|
|
25
25
|
"EventsTable",
|
|
26
26
|
"JoinTable",
|
|
27
|
+
"OtelTables",
|
|
27
28
|
"RefreshedView",
|
|
28
29
|
"ReplacingTable",
|
|
29
30
|
"RollupView",
|
|
30
31
|
"ShardedTable",
|
|
31
32
|
"SoftDeleteTable",
|
|
33
|
+
"StreamIngest",
|
|
32
34
|
"TenantTable",
|
|
33
35
|
]);
|
|
34
36
|
expect(catalogued, "regenerate with `npm run generate:composite-catalogs -- sql`").toEqual(exported);
|
|
@@ -47,11 +49,14 @@ describe("the sql composite catalog", () => {
|
|
|
47
49
|
ReplacingTable: ["ClickHouseTable"],
|
|
48
50
|
RollupView: ["ClickHouseTable", "ClickHouseView"],
|
|
49
51
|
ShardedTable: ["ClickHouseTable"],
|
|
52
|
+
OtelTables: ["ClickHouseTable", "ClickHouseView"],
|
|
53
|
+
StreamIngest: ["ClickHouseTable", "ClickHouseView"],
|
|
50
54
|
});
|
|
51
55
|
for (const entry of compositeCatalog) {
|
|
52
56
|
expect(entry.lexicon, entry.name).toBe("sql");
|
|
53
57
|
expect(entry.description.length, entry.name).toBeGreaterThan(0);
|
|
54
|
-
|
|
58
|
+
// OtelTables declares a fixed set of tables, so it takes no name.
|
|
59
|
+
if (entry.name !== "OtelTables") expect(entry.params.find((p) => p.name === "name")?.required, entry.name).toBe(true);
|
|
55
60
|
}
|
|
56
61
|
});
|
|
57
62
|
|
|
@@ -215,6 +215,41 @@ export const compositeCatalog: CompositeEntry[] = [
|
|
|
215
215
|
}
|
|
216
216
|
]
|
|
217
217
|
},
|
|
218
|
+
{
|
|
219
|
+
"name": "OtelTables",
|
|
220
|
+
"lexicon": "sql",
|
|
221
|
+
"description": "The logs, traces and metrics tables the OpenTelemetry Collector's clickhouse exporter writes, as it creates them at v0.130.0.",
|
|
222
|
+
"bundles": [
|
|
223
|
+
"ClickHouseTable",
|
|
224
|
+
"ClickHouseView"
|
|
225
|
+
],
|
|
226
|
+
"params": [
|
|
227
|
+
{
|
|
228
|
+
"name": "database",
|
|
229
|
+
"type": "string",
|
|
230
|
+
"required": false,
|
|
231
|
+
"description": "The database the tables are created in, the exporter's `database`."
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
"name": "ttl",
|
|
235
|
+
"type": "string",
|
|
236
|
+
"required": false,
|
|
237
|
+
"description": "How long rows are kept, as the exporter's `ttl` takes it: a Go duration such as `72h` or `30m`."
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
"name": "tables",
|
|
241
|
+
"type": "OtelTableNames",
|
|
242
|
+
"required": false,
|
|
243
|
+
"description": "Table names other than the exporter's defaults, as set on the exporter."
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
"name": "traceIdLookup",
|
|
247
|
+
"type": "boolean",
|
|
248
|
+
"required": false,
|
|
249
|
+
"description": "Declare the trace-id lookup table and its materialized view (default true)."
|
|
250
|
+
}
|
|
251
|
+
]
|
|
252
|
+
},
|
|
218
253
|
{
|
|
219
254
|
"name": "RefreshedView",
|
|
220
255
|
"lexicon": "sql",
|
|
@@ -473,6 +508,71 @@ export const compositeCatalog: CompositeEntry[] = [
|
|
|
473
508
|
}
|
|
474
509
|
]
|
|
475
510
|
},
|
|
511
|
+
{
|
|
512
|
+
"name": "StreamIngest",
|
|
513
|
+
"lexicon": "sql",
|
|
514
|
+
"description": "A stream table, the materialized view that reads it, and the MergeTree target the view writes.",
|
|
515
|
+
"bundles": [
|
|
516
|
+
"ClickHouseTable",
|
|
517
|
+
"ClickHouseView"
|
|
518
|
+
],
|
|
519
|
+
"params": [
|
|
520
|
+
{
|
|
521
|
+
"name": "name",
|
|
522
|
+
"type": "string",
|
|
523
|
+
"required": true,
|
|
524
|
+
"description": "The target table's name."
|
|
525
|
+
},
|
|
526
|
+
{
|
|
527
|
+
"name": "columns",
|
|
528
|
+
"type": "string",
|
|
529
|
+
"required": true,
|
|
530
|
+
"description": "The target's columns, as SQL: `ts DateTime, user_id UInt64, kind LowCardinality(String)`."
|
|
531
|
+
},
|
|
532
|
+
{
|
|
533
|
+
"name": "engine",
|
|
534
|
+
"type": "string",
|
|
535
|
+
"required": true,
|
|
536
|
+
"description": "The stream table's engine, with a named collection as its first argument rather than inline credentials: `Kafka(kafka_creds)`, `S3Queue(lake_creds)`."
|
|
537
|
+
},
|
|
538
|
+
{
|
|
539
|
+
"name": "settings",
|
|
540
|
+
"type": "string",
|
|
541
|
+
"required": false,
|
|
542
|
+
"description": "The engine's settings, the body of a `SETTINGS` clause: `kafka_topic_list = 'events', kafka_group_name = 'ingest', kafka_format = 'JSONEachRow'`."
|
|
543
|
+
},
|
|
544
|
+
{
|
|
545
|
+
"name": "streamColumns",
|
|
546
|
+
"type": "string",
|
|
547
|
+
"required": false,
|
|
548
|
+
"description": "The stream table's columns when they differ from the target's: the message as it arrives."
|
|
549
|
+
},
|
|
550
|
+
{
|
|
551
|
+
"name": "select",
|
|
552
|
+
"type": "string",
|
|
553
|
+
"required": false,
|
|
554
|
+
"description": "The view's select list over the stream table, each item aliased to a target column."
|
|
555
|
+
},
|
|
556
|
+
{
|
|
557
|
+
"name": "orderBy",
|
|
558
|
+
"type": "string",
|
|
559
|
+
"required": true,
|
|
560
|
+
"description": "The target's sort key (a column list or an expression)."
|
|
561
|
+
},
|
|
562
|
+
{
|
|
563
|
+
"name": "targetEngine",
|
|
564
|
+
"type": "string",
|
|
565
|
+
"required": false,
|
|
566
|
+
"description": "The target's engine (default `MergeTree`)."
|
|
567
|
+
},
|
|
568
|
+
{
|
|
569
|
+
"name": "partitionBy",
|
|
570
|
+
"type": "string",
|
|
571
|
+
"required": false,
|
|
572
|
+
"description": "The target's partition key."
|
|
573
|
+
}
|
|
574
|
+
]
|
|
575
|
+
},
|
|
476
576
|
{
|
|
477
577
|
"name": "TenantTable",
|
|
478
578
|
"lexicon": "sql",
|
|
@@ -5,3 +5,5 @@ export { EventsTable, type EventsTableProps, type EventsTableMembers } from "./e
|
|
|
5
5
|
export { RollupView, type RollupViewProps, type RollupViewMembers } from "./rollup-view";
|
|
6
6
|
export { CdcMirror, type CdcMirrorProps, type CdcMirrorMembers } from "./cdc-mirror";
|
|
7
7
|
export { ShardedTable, type ShardedTableProps, type ShardedTableMembers } from "./sharded-table";
|
|
8
|
+
export { OtelTables, OTEL_EXPORTER_DEFAULT_TABLES, otelTtlClause, type OtelTablesProps, type OtelTablesMembers, type OtelTableNames } from "./otel-tables";
|
|
9
|
+
export { StreamIngest, type StreamIngestProps, type StreamIngestMembers } from "./stream-ingest";
|
|
@@ -234,7 +234,7 @@ describe("the composites pass the lexicon's post-synth checks", () => {
|
|
|
234
234
|
const ids = clickhouse.map((c) => c.id).sort();
|
|
235
235
|
expect(ids[0]).toBe("SQL101");
|
|
236
236
|
expect(ids).toContain("SQLCH101");
|
|
237
|
-
expect(ids.at(-1)).toBe("
|
|
237
|
+
expect(ids.at(-1)).toBe("SQLCH128");
|
|
238
238
|
expect(clickhouse.flatMap((check) => check.check(ctx))).toEqual([]);
|
|
239
239
|
});
|
|
240
240
|
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `OtelTables` (#4397): the tables the OpenTelemetry Collector's clickhouse
|
|
3
|
+
* exporter writes, as its create statements at contrib v0.130.0 declare them.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { describe, expect, test } from "vitest";
|
|
7
|
+
import { expandComposite } from "@intentius/chant/composite";
|
|
8
|
+
import type { Declarable } from "@intentius/chant/declarable";
|
|
9
|
+
import type { SerializerResult } from "@intentius/chant/serializer";
|
|
10
|
+
import { makePostSynthCtx } from "@intentius/chant-test-utils";
|
|
11
|
+
import { CLICKHOUSE_ENTITY_TYPES, type ClickHouseObject, type ClickHouseTable, type TableProps, type ViewProps } from "../clickhouse/entities";
|
|
12
|
+
import { sqlSerializer } from "../serializer";
|
|
13
|
+
import { postSynthChecks } from "../lint/post-synth";
|
|
14
|
+
import { sqlWorkspaceOutputs } from "../workspace-outputs";
|
|
15
|
+
import { OtelTables, otelTtlClause } from "./index";
|
|
16
|
+
|
|
17
|
+
const props = (e: unknown) => (e as ClickHouseObject & { props: TableProps }).props;
|
|
18
|
+
const columns = (e: unknown) => props(e).columns.map((c) => c.name);
|
|
19
|
+
|
|
20
|
+
describe("OtelTables", () => {
|
|
21
|
+
test("defaults: the exporter's seven tables, unqualified, plus the trace-id lookup table and view", () => {
|
|
22
|
+
const t = OtelTables({});
|
|
23
|
+
expect(Object.entries(t).map(([k, e]) => [k, (e as Declarable).entityType, props(e).database, props(e).name])).toEqual([
|
|
24
|
+
["logs", CLICKHOUSE_ENTITY_TYPES.table, undefined, "otel_logs"],
|
|
25
|
+
["traces", CLICKHOUSE_ENTITY_TYPES.table, undefined, "otel_traces"],
|
|
26
|
+
["metricsGauge", CLICKHOUSE_ENTITY_TYPES.table, undefined, "otel_metrics_gauge"],
|
|
27
|
+
["metricsSum", CLICKHOUSE_ENTITY_TYPES.table, undefined, "otel_metrics_sum"],
|
|
28
|
+
["metricsSummary", CLICKHOUSE_ENTITY_TYPES.table, undefined, "otel_metrics_summary"],
|
|
29
|
+
["metricsHistogram", CLICKHOUSE_ENTITY_TYPES.table, undefined, "otel_metrics_histogram"],
|
|
30
|
+
["metricsExponentialHistogram", CLICKHOUSE_ENTITY_TYPES.table, undefined, "otel_metrics_exponential_histogram"],
|
|
31
|
+
["traceIdTs", CLICKHOUSE_ENTITY_TYPES.table, undefined, "otel_traces_trace_id_ts"],
|
|
32
|
+
["traceIdTsView", CLICKHOUSE_ENTITY_TYPES.materializedView, undefined, "otel_traces_trace_id_ts_mv"],
|
|
33
|
+
]);
|
|
34
|
+
expect(props(t.logs).ttl).toBeUndefined();
|
|
35
|
+
expect(props(t.logs).engine).toEqual({ name: "MergeTree" });
|
|
36
|
+
expect(props(t.logs).settings).toEqual({ index_granularity: "8192", ttl_only_drop_parts: "1" });
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("the columns of the exporter's create statements, in their order", () => {
|
|
40
|
+
const t = OtelTables({});
|
|
41
|
+
expect(columns(t.logs)).toEqual([
|
|
42
|
+
"Timestamp", "TimestampTime", "TraceId", "SpanId", "TraceFlags", "SeverityText", "SeverityNumber", "ServiceName", "Body",
|
|
43
|
+
"ResourceSchemaUrl", "ResourceAttributes", "ScopeSchemaUrl", "ScopeName", "ScopeVersion", "ScopeAttributes", "LogAttributes",
|
|
44
|
+
]);
|
|
45
|
+
expect(columns(t.traces)).toEqual([
|
|
46
|
+
"Timestamp", "TraceId", "SpanId", "ParentSpanId", "TraceState", "SpanName", "SpanKind", "ServiceName", "ResourceAttributes",
|
|
47
|
+
"ScopeName", "ScopeVersion", "SpanAttributes", "Duration", "StatusCode", "StatusMessage", "Events", "Links",
|
|
48
|
+
]);
|
|
49
|
+
const head = [
|
|
50
|
+
"ResourceAttributes", "ResourceSchemaUrl", "ScopeName", "ScopeVersion", "ScopeAttributes", "ScopeDroppedAttrCount", "ScopeSchemaUrl",
|
|
51
|
+
"ServiceName", "MetricName", "MetricDescription", "MetricUnit", "Attributes", "StartTimeUnix", "TimeUnix",
|
|
52
|
+
];
|
|
53
|
+
expect(columns(t.metricsGauge)).toEqual([...head, "Value", "Flags", "Exemplars"]);
|
|
54
|
+
expect(columns(t.metricsSum)).toEqual([...head, "Value", "Flags", "Exemplars", "AggregationTemporality", "IsMonotonic"]);
|
|
55
|
+
expect(columns(t.metricsSummary)).toEqual([...head, "Count", "Sum", "ValueAtQuantiles", "Flags"]);
|
|
56
|
+
expect(columns(t.metricsHistogram)).toEqual([...head, "Count", "Sum", "BucketCounts", "ExplicitBounds", "Exemplars", "Flags", "Min", "Max", "AggregationTemporality"]);
|
|
57
|
+
expect(columns(t.metricsExponentialHistogram)).toEqual([
|
|
58
|
+
...head, "Count", "Sum", "Scale", "ZeroCount", "PositiveOffset", "PositiveBucketCounts", "NegativeOffset", "NegativeBucketCounts",
|
|
59
|
+
"Exemplars", "Flags", "Min", "Max", "AggregationTemporality",
|
|
60
|
+
]);
|
|
61
|
+
expect(columns(t.traceIdTs)).toEqual(["TraceId", "Start", "End"]);
|
|
62
|
+
expect(props(t.logs).columns.find((c) => c.name === "Timestamp")?.codec).toBe("Delta(8), ZSTD(1)");
|
|
63
|
+
expect(props(t.traces).columns.find((c) => c.name === "Events")?.type?.replace(/\s+/g, " ")).toBe(
|
|
64
|
+
"Nested ( Timestamp DateTime64(9), Name LowCardinality(String), Attributes Map(LowCardinality(String), String) )",
|
|
65
|
+
);
|
|
66
|
+
expect(props(t.logs).indexes.map((i) => i.name)).toEqual([
|
|
67
|
+
"idx_trace_id", "idx_res_attr_key", "idx_res_attr_value", "idx_scope_attr_key", "idx_scope_attr_value", "idx_log_attr_key", "idx_log_attr_value", "idx_body",
|
|
68
|
+
]);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("database, ttl and table names reach every member; the view reads the traces table into the lookup table", () => {
|
|
72
|
+
const t = OtelTables({ database: "otel", ttl: "72h", tables: { traces: "spans", exponentialHistogram: "otel_metrics_exp_histogram" } });
|
|
73
|
+
expect(props(t.traces)).toMatchObject({ database: "otel", name: "spans", ttl: "toDateTime(Timestamp) + toIntervalDay(3)" });
|
|
74
|
+
expect(props(t.logs).ttl).toBe("TimestampTime + toIntervalDay(3)");
|
|
75
|
+
expect(props(t.metricsExponentialHistogram)).toMatchObject({ name: "otel_metrics_exp_histogram", ttl: "toDateTime(TimeUnix) + toIntervalDay(3)" });
|
|
76
|
+
expect(props(t.traceIdTs)).toMatchObject({ database: "otel", name: "spans_trace_id_ts", ttl: "toDateTime(Start) + toIntervalDay(3)" });
|
|
77
|
+
const view = (t.traceIdTsView as unknown as { props: ViewProps }).props;
|
|
78
|
+
expect(view.name).toBe("spans_trace_id_ts_mv");
|
|
79
|
+
expect(view.to).toBe(t.traceIdTs);
|
|
80
|
+
expect(view.reads).toEqual([t.traces]);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("traceIdLookup: false leaves out the lookup table and view", () => {
|
|
84
|
+
const t = OtelTables({ traceIdLookup: false });
|
|
85
|
+
expect(Object.keys(t)).not.toContain("traceIdTs");
|
|
86
|
+
expect(Object.keys(t)).not.toContain("traceIdTsView");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("the TTL is rendered as the exporter's GenerateTTLExpr renders it", () => {
|
|
90
|
+
expect(otelTtlClause(undefined, "t")).toBe("");
|
|
91
|
+
expect(otelTtlClause("0", "t")).toBe("");
|
|
92
|
+
expect(otelTtlClause("48h", "t")).toBe("TTL t + toIntervalDay(2)");
|
|
93
|
+
expect(otelTtlClause("12h", "t")).toBe("TTL t + toIntervalHour(12)");
|
|
94
|
+
expect(otelTtlClause("1h30m", "t")).toBe("TTL t + toIntervalMinute(90)");
|
|
95
|
+
expect(otelTtlClause("90s", "t")).toBe("TTL t + toIntervalSecond(90)");
|
|
96
|
+
expect(() => otelTtlClause("3d", "t")).toThrow(/not a Go duration/);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("passes the lexicon's post-synth checks, and orders the view after both tables", () => {
|
|
100
|
+
const entities = new Map<string, Declarable>();
|
|
101
|
+
for (const [k, v] of expandComposite("otel", OtelTables({ database: "otel", ttl: "72h" }))) entities.set(k, v);
|
|
102
|
+
const out = sqlSerializer.serialize(entities) as SerializerResult;
|
|
103
|
+
const doc = JSON.parse(out.primary) as { applyOrder: string[] };
|
|
104
|
+
expect(doc.applyOrder.indexOf("otelTraces")).toBeLessThan(doc.applyOrder.indexOf("otelTraceIdTsView"));
|
|
105
|
+
expect(doc.applyOrder.indexOf("otelTraceIdTs")).toBeLessThan(doc.applyOrder.indexOf("otelTraceIdTsView"));
|
|
106
|
+
const ctx = makePostSynthCtx("sql", out.primary, entities);
|
|
107
|
+
const checks = postSynthChecks.filter((c) => c.id.startsWith("SQLCH") || c.id === "SQL101");
|
|
108
|
+
expect(checks.flatMap((check) => check.check(ctx))).toEqual([]);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("its tables and columns are workspace outputs another member can link to", () => {
|
|
112
|
+
const entities = new Map<string, Declarable>();
|
|
113
|
+
for (const [k, v] of expandComposite("otel", OtelTables({ database: "otel" }))) entities.set(k, v);
|
|
114
|
+
const names = sqlWorkspaceOutputs(entities)!.outputs.map((o) => o.name);
|
|
115
|
+
expect(names).toEqual(expect.arrayContaining(["otel.otel_logs", "otel.otel_logs.Body", "otel.otel_traces.Events", "otel.otel_traces_trace_id_ts_mv"]));
|
|
116
|
+
expect((OtelTables({}).logs as ClickHouseTable).entityType).toBe(CLICKHOUSE_ENTITY_TYPES.table);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `OtelTables`: the tables the OpenTelemetry Collector's `clickhouse` exporter writes, declared here so the exporter can run with `create_schema: false`.
|
|
3
|
+
*
|
|
4
|
+
* The DDL follows the exporter's own create statements at
|
|
5
|
+
* opentelemetry-collector-contrib v0.130.0, the otel lexicon's
|
|
6
|
+
* `COLLECTOR_PIN`, column for column:
|
|
7
|
+
*
|
|
8
|
+
* - `exporter/clickhouseexporter/internal/sqltemplates/logs_table.sql`
|
|
9
|
+
* - `exporter/clickhouseexporter/internal/sqltemplates/traces_table.sql`
|
|
10
|
+
* - `exporter/clickhouseexporter/internal/sqltemplates/traces_id_ts_lookup_table.sql`
|
|
11
|
+
* - `exporter/clickhouseexporter/internal/sqltemplates/traces_id_ts_lookup_mv.sql`
|
|
12
|
+
* - `exporter/clickhouseexporter/internal/sqltemplates/metrics_gauge_table.sql`,
|
|
13
|
+
* `metrics_sum_table.sql`, `metrics_summary_table.sql`,
|
|
14
|
+
* `metrics_histogram_table.sql` and `metrics_exp_histogram_table.sql`
|
|
15
|
+
*
|
|
16
|
+
* The table names default to the exporter's (`exporter/clickhouseexporter/config.go`,
|
|
17
|
+
* `createDefaultConfig`): `otel_logs`, `otel_traces` and `otel_metrics_<type>`.
|
|
18
|
+
* The exponential histogram table is `otel_metrics_exponential_histogram`:
|
|
19
|
+
* `defaultExpHistogramSuffix` in config.go is `_exponential_histogram`, though
|
|
20
|
+
* the README's option list says `otel_metrics_exp_histogram`. The code decides.
|
|
21
|
+
*
|
|
22
|
+
* With `create_schema: true` the exporter's traces exporter also creates a
|
|
23
|
+
* trace-id lookup table, `<traces>_trace_id_ts`, and a materialized view,
|
|
24
|
+
* `<traces>_trace_id_ts_mv`, that fills it from the traces table
|
|
25
|
+
* (`createTraceTables` in `exporter_traces.go`). The README's trace query
|
|
26
|
+
* reads the lookup table to bound a trace's time range. Both are declared
|
|
27
|
+
* here unless `traceIdLookup` is false.
|
|
28
|
+
*
|
|
29
|
+
* What differs from the exporter's DDL, none of it a column:
|
|
30
|
+
*
|
|
31
|
+
* - The engine is `MergeTree`, the exporter's default `table_engine`. A
|
|
32
|
+
* replicated setup declares its own tables.
|
|
33
|
+
* - `IF NOT EXISTS` and `ON CLUSTER` are left out; the sql lexicon plans the
|
|
34
|
+
* tables instead.
|
|
35
|
+
* - The metrics templates put `TTL` before `PARTITION BY`; here it follows
|
|
36
|
+
* `ORDER BY`, as in the logs and traces templates. ClickHouse reads the
|
|
37
|
+
* clauses the same in either order.
|
|
38
|
+
* - The exporter's JSON tables (`logs_json_table.sql`, `traces_json_table.sql`)
|
|
39
|
+
* are used only behind the `clickhouse.json` feature gate (alpha, off by
|
|
40
|
+
* default, `factory.go`) and are not declared.
|
|
41
|
+
*
|
|
42
|
+
* The database is not declared. Unqualified, the tables are created in the
|
|
43
|
+
* server's `default` database, which is the exporter's default `database`.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
import { Composite } from "@intentius/chant/composite";
|
|
47
|
+
import { table, view, type ClickHouseTable, type ClickHouseView } from "../clickhouse/entities";
|
|
48
|
+
|
|
49
|
+
/** The table names the exporter writes, by its config key. Each defaults to the exporter's. */
|
|
50
|
+
export interface OtelTableNames {
|
|
51
|
+
/** `logs_table_name` (default `otel_logs`). */
|
|
52
|
+
logs?: string;
|
|
53
|
+
/** `traces_table_name` (default `otel_traces`). */
|
|
54
|
+
traces?: string;
|
|
55
|
+
/** `metrics_tables.gauge.name` (default `otel_metrics_gauge`). */
|
|
56
|
+
gauge?: string;
|
|
57
|
+
/** `metrics_tables.sum.name` (default `otel_metrics_sum`). */
|
|
58
|
+
sum?: string;
|
|
59
|
+
/** `metrics_tables.summary.name` (default `otel_metrics_summary`). */
|
|
60
|
+
summary?: string;
|
|
61
|
+
/** `metrics_tables.histogram.name` (default `otel_metrics_histogram`). */
|
|
62
|
+
histogram?: string;
|
|
63
|
+
/** `metrics_tables.exponential_histogram.name` (default `otel_metrics_exponential_histogram`). */
|
|
64
|
+
exponentialHistogram?: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface OtelTablesProps {
|
|
68
|
+
/** The database the tables are created in, the exporter's `database`. Unset, the names are unqualified and land in `default`. */
|
|
69
|
+
database?: string;
|
|
70
|
+
/**
|
|
71
|
+
* How long rows are kept, as the exporter's `ttl` takes it: a Go duration
|
|
72
|
+
* such as `72h` or `30m`. Rendered the way the exporter renders it
|
|
73
|
+
* (`GenerateTTLExpr` in `internal/clickhouse.go`): whole days as
|
|
74
|
+
* `toIntervalDay`, else hours, minutes or seconds. Unset or zero, no TTL.
|
|
75
|
+
*/
|
|
76
|
+
ttl?: string;
|
|
77
|
+
/** Table names other than the exporter's defaults, as set on the exporter. */
|
|
78
|
+
tables?: OtelTableNames;
|
|
79
|
+
/** Declare the trace-id lookup table and its materialized view (default true). */
|
|
80
|
+
traceIdLookup?: boolean;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export type OtelTablesMembers = {
|
|
84
|
+
logs: ClickHouseTable;
|
|
85
|
+
traces: ClickHouseTable;
|
|
86
|
+
/** `<traces>_trace_id_ts`, absent when `traceIdLookup` is false. */
|
|
87
|
+
traceIdTs?: ClickHouseTable;
|
|
88
|
+
/** `<traces>_trace_id_ts_mv`, absent when `traceIdLookup` is false. */
|
|
89
|
+
traceIdTsView?: ClickHouseView;
|
|
90
|
+
metricsGauge: ClickHouseTable;
|
|
91
|
+
metricsSum: ClickHouseTable;
|
|
92
|
+
metricsSummary: ClickHouseTable;
|
|
93
|
+
metricsHistogram: ClickHouseTable;
|
|
94
|
+
metricsExponentialHistogram: ClickHouseTable;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/** The exporter's default table names at v0.130.0 (`createDefaultConfig` in `config.go`). */
|
|
98
|
+
export const OTEL_EXPORTER_DEFAULT_TABLES: Readonly<Required<OtelTableNames>> = Object.freeze({
|
|
99
|
+
logs: "otel_logs",
|
|
100
|
+
traces: "otel_traces",
|
|
101
|
+
gauge: "otel_metrics_gauge",
|
|
102
|
+
sum: "otel_metrics_sum",
|
|
103
|
+
summary: "otel_metrics_summary",
|
|
104
|
+
histogram: "otel_metrics_histogram",
|
|
105
|
+
exponentialHistogram: "otel_metrics_exponential_histogram",
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const GO_UNITS_S: Record<string, number> = { ns: 1e-9, us: 1e-6, "µs": 1e-6, "μs": 1e-6, ms: 1e-3, s: 1, m: 60, h: 3600 };
|
|
109
|
+
|
|
110
|
+
/** A Go duration in whole seconds, or an error naming the value. Go's `time.ParseDuration` has no day unit. */
|
|
111
|
+
function goDurationSeconds(d: string): number {
|
|
112
|
+
const text = d.trim();
|
|
113
|
+
if (/^0$/.test(text)) return 0;
|
|
114
|
+
if (!/^((\d+(\.\d*)?|\.\d+)(ns|us|µs|μs|ms|s|m|h))+$/.test(text)) {
|
|
115
|
+
throw new Error(`OtelTables: ttl ${JSON.stringify(d)} is not a Go duration such as 72h or 30m`);
|
|
116
|
+
}
|
|
117
|
+
let total = 0;
|
|
118
|
+
for (const part of text.matchAll(/(\d+(?:\.\d*)?|\.\d+)(ns|us|µs|μs|ms|s|m|h)/g)) total += Number(part[1]) * GO_UNITS_S[part[2]!]!;
|
|
119
|
+
return Math.floor(total);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The TTL clause the exporter writes for `ttl` over `timeField`, or "" for none
|
|
124
|
+
* (`GenerateTTLExpr` in `internal/clickhouse.go` at v0.130.0).
|
|
125
|
+
*/
|
|
126
|
+
export function otelTtlClause(ttl: string | undefined, timeField: string): string {
|
|
127
|
+
if (ttl === undefined) return "";
|
|
128
|
+
const s = goDurationSeconds(ttl);
|
|
129
|
+
if (s <= 0) return "";
|
|
130
|
+
if (s % 86400 === 0) return `TTL ${timeField} + toIntervalDay(${s / 86400})`;
|
|
131
|
+
if (s % 3600 === 0) return `TTL ${timeField} + toIntervalHour(${s / 3600})`;
|
|
132
|
+
if (s % 60 === 0) return `TTL ${timeField} + toIntervalMinute(${s / 60})`;
|
|
133
|
+
return `TTL ${timeField} + toIntervalSecond(${s})`;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// The column lists of the exporter's create statements, as written there.
|
|
137
|
+
|
|
138
|
+
const METRIC_HEAD = `
|
|
139
|
+
ResourceAttributes Map(LowCardinality(String), String) CODEC(ZSTD(1)),
|
|
140
|
+
ResourceSchemaUrl String CODEC(ZSTD(1)),
|
|
141
|
+
ScopeName String CODEC(ZSTD(1)),
|
|
142
|
+
ScopeVersion String CODEC(ZSTD(1)),
|
|
143
|
+
ScopeAttributes Map(LowCardinality(String), String) CODEC(ZSTD(1)),
|
|
144
|
+
ScopeDroppedAttrCount UInt32 CODEC(ZSTD(1)),
|
|
145
|
+
ScopeSchemaUrl String CODEC(ZSTD(1)),
|
|
146
|
+
ServiceName LowCardinality(String) CODEC(ZSTD(1)),
|
|
147
|
+
MetricName String CODEC(ZSTD(1)),
|
|
148
|
+
MetricDescription String CODEC(ZSTD(1)),
|
|
149
|
+
MetricUnit String CODEC(ZSTD(1)),
|
|
150
|
+
Attributes Map(LowCardinality(String), String) CODEC(ZSTD(1)),
|
|
151
|
+
StartTimeUnix DateTime64(9) CODEC(Delta, ZSTD(1)),
|
|
152
|
+
TimeUnix DateTime64(9) CODEC(Delta, ZSTD(1)),`;
|
|
153
|
+
|
|
154
|
+
const EXEMPLARS = `
|
|
155
|
+
Exemplars Nested (
|
|
156
|
+
FilteredAttributes Map(LowCardinality(String), String),
|
|
157
|
+
TimeUnix DateTime64(9),
|
|
158
|
+
Value Float64,
|
|
159
|
+
SpanId String,
|
|
160
|
+
TraceId String
|
|
161
|
+
) CODEC(ZSTD(1)),`;
|
|
162
|
+
|
|
163
|
+
const METRIC_INDEXES = `
|
|
164
|
+
INDEX idx_res_attr_key mapKeys(ResourceAttributes) TYPE bloom_filter(0.01) GRANULARITY 1,
|
|
165
|
+
INDEX idx_res_attr_value mapValues(ResourceAttributes) TYPE bloom_filter(0.01) GRANULARITY 1,
|
|
166
|
+
INDEX idx_scope_attr_key mapKeys(ScopeAttributes) TYPE bloom_filter(0.01) GRANULARITY 1,
|
|
167
|
+
INDEX idx_scope_attr_value mapValues(ScopeAttributes) TYPE bloom_filter(0.01) GRANULARITY 1,
|
|
168
|
+
INDEX idx_attr_key mapKeys(Attributes) TYPE bloom_filter(0.01) GRANULARITY 1,
|
|
169
|
+
INDEX idx_attr_value mapValues(Attributes) TYPE bloom_filter(0.01) GRANULARITY 1`;
|
|
170
|
+
|
|
171
|
+
/** The columns each metric table adds between the shared head and the indexes. */
|
|
172
|
+
const METRIC_BODIES = {
|
|
173
|
+
gauge: `
|
|
174
|
+
Value Float64 CODEC(ZSTD(1)),
|
|
175
|
+
Flags UInt32 CODEC(ZSTD(1)),${EXEMPLARS}`,
|
|
176
|
+
sum: `
|
|
177
|
+
Value Float64 CODEC(ZSTD(1)),
|
|
178
|
+
Flags UInt32 CODEC(ZSTD(1)),${EXEMPLARS}
|
|
179
|
+
AggregationTemporality Int32 CODEC(ZSTD(1)),
|
|
180
|
+
IsMonotonic Boolean CODEC(Delta, ZSTD(1)),`,
|
|
181
|
+
summary: `
|
|
182
|
+
Count UInt64 CODEC(Delta, ZSTD(1)),
|
|
183
|
+
Sum Float64 CODEC(ZSTD(1)),
|
|
184
|
+
ValueAtQuantiles Nested (
|
|
185
|
+
Quantile Float64,
|
|
186
|
+
Value Float64
|
|
187
|
+
) CODEC(ZSTD(1)),
|
|
188
|
+
Flags UInt32 CODEC(ZSTD(1)),`,
|
|
189
|
+
histogram: `
|
|
190
|
+
Count UInt64 CODEC(Delta, ZSTD(1)),
|
|
191
|
+
Sum Float64 CODEC(ZSTD(1)),
|
|
192
|
+
BucketCounts Array(UInt64) CODEC(ZSTD(1)),
|
|
193
|
+
ExplicitBounds Array(Float64) CODEC(ZSTD(1)),${EXEMPLARS}
|
|
194
|
+
Flags UInt32 CODEC(ZSTD(1)),
|
|
195
|
+
Min Float64 CODEC(ZSTD(1)),
|
|
196
|
+
Max Float64 CODEC(ZSTD(1)),
|
|
197
|
+
AggregationTemporality Int32 CODEC(ZSTD(1)),`,
|
|
198
|
+
exponentialHistogram: `
|
|
199
|
+
Count UInt64 CODEC(Delta, ZSTD(1)),
|
|
200
|
+
Sum Float64 CODEC(ZSTD(1)),
|
|
201
|
+
Scale Int32 CODEC(ZSTD(1)),
|
|
202
|
+
ZeroCount UInt64 CODEC(ZSTD(1)),
|
|
203
|
+
PositiveOffset Int32 CODEC(ZSTD(1)),
|
|
204
|
+
PositiveBucketCounts Array(UInt64) CODEC(ZSTD(1)),
|
|
205
|
+
NegativeOffset Int32 CODEC(ZSTD(1)),
|
|
206
|
+
NegativeBucketCounts Array(UInt64) CODEC(ZSTD(1)),${EXEMPLARS}
|
|
207
|
+
Flags UInt32 CODEC(ZSTD(1)),
|
|
208
|
+
Min Float64 CODEC(ZSTD(1)),
|
|
209
|
+
Max Float64 CODEC(ZSTD(1)),
|
|
210
|
+
AggregationTemporality Int32 CODEC(ZSTD(1)),`,
|
|
211
|
+
} as const;
|
|
212
|
+
|
|
213
|
+
/** The logs, traces and metrics tables the OpenTelemetry Collector's clickhouse exporter writes, as it creates them at v0.130.0. */
|
|
214
|
+
export const OtelTables = Composite<OtelTablesProps, OtelTablesMembers>((props) => {
|
|
215
|
+
const names = { ...OTEL_EXPORTER_DEFAULT_TABLES, ...props.tables };
|
|
216
|
+
const q = (name: string) => (props.database ? `${props.database}.${name}` : name);
|
|
217
|
+
const ttl = (field: string) => otelTtlClause(props.ttl, field);
|
|
218
|
+
|
|
219
|
+
const logs = table`
|
|
220
|
+
CREATE TABLE ${q(names.logs)} (
|
|
221
|
+
Timestamp DateTime64(9) CODEC(Delta(8), ZSTD(1)),
|
|
222
|
+
TimestampTime DateTime DEFAULT toDateTime(Timestamp),
|
|
223
|
+
TraceId String CODEC(ZSTD(1)),
|
|
224
|
+
SpanId String CODEC(ZSTD(1)),
|
|
225
|
+
TraceFlags UInt8,
|
|
226
|
+
SeverityText LowCardinality(String) CODEC(ZSTD(1)),
|
|
227
|
+
SeverityNumber UInt8,
|
|
228
|
+
ServiceName LowCardinality(String) CODEC(ZSTD(1)),
|
|
229
|
+
Body String CODEC(ZSTD(1)),
|
|
230
|
+
ResourceSchemaUrl LowCardinality(String) CODEC(ZSTD(1)),
|
|
231
|
+
ResourceAttributes Map(LowCardinality(String), String) CODEC(ZSTD(1)),
|
|
232
|
+
ScopeSchemaUrl LowCardinality(String) CODEC(ZSTD(1)),
|
|
233
|
+
ScopeName String CODEC(ZSTD(1)),
|
|
234
|
+
ScopeVersion LowCardinality(String) CODEC(ZSTD(1)),
|
|
235
|
+
ScopeAttributes Map(LowCardinality(String), String) CODEC(ZSTD(1)),
|
|
236
|
+
LogAttributes Map(LowCardinality(String), String) CODEC(ZSTD(1)),
|
|
237
|
+
INDEX idx_trace_id TraceId TYPE bloom_filter(0.001) GRANULARITY 1,
|
|
238
|
+
INDEX idx_res_attr_key mapKeys(ResourceAttributes) TYPE bloom_filter(0.01) GRANULARITY 1,
|
|
239
|
+
INDEX idx_res_attr_value mapValues(ResourceAttributes) TYPE bloom_filter(0.01) GRANULARITY 1,
|
|
240
|
+
INDEX idx_scope_attr_key mapKeys(ScopeAttributes) TYPE bloom_filter(0.01) GRANULARITY 1,
|
|
241
|
+
INDEX idx_scope_attr_value mapValues(ScopeAttributes) TYPE bloom_filter(0.01) GRANULARITY 1,
|
|
242
|
+
INDEX idx_log_attr_key mapKeys(LogAttributes) TYPE bloom_filter(0.01) GRANULARITY 1,
|
|
243
|
+
INDEX idx_log_attr_value mapValues(LogAttributes) TYPE bloom_filter(0.01) GRANULARITY 1,
|
|
244
|
+
INDEX idx_body Body TYPE tokenbf_v1(32768, 3, 0) GRANULARITY 8
|
|
245
|
+
)
|
|
246
|
+
ENGINE = MergeTree
|
|
247
|
+
PARTITION BY toDate(TimestampTime)
|
|
248
|
+
PRIMARY KEY (ServiceName, TimestampTime)
|
|
249
|
+
ORDER BY (ServiceName, TimestampTime, Timestamp)
|
|
250
|
+
${ttl("TimestampTime")}
|
|
251
|
+
SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1`;
|
|
252
|
+
|
|
253
|
+
const traces = table`
|
|
254
|
+
CREATE TABLE ${q(names.traces)} (
|
|
255
|
+
Timestamp DateTime64(9) CODEC(Delta, ZSTD(1)),
|
|
256
|
+
TraceId String CODEC(ZSTD(1)),
|
|
257
|
+
SpanId String CODEC(ZSTD(1)),
|
|
258
|
+
ParentSpanId String CODEC(ZSTD(1)),
|
|
259
|
+
TraceState String CODEC(ZSTD(1)),
|
|
260
|
+
SpanName LowCardinality(String) CODEC(ZSTD(1)),
|
|
261
|
+
SpanKind LowCardinality(String) CODEC(ZSTD(1)),
|
|
262
|
+
ServiceName LowCardinality(String) CODEC(ZSTD(1)),
|
|
263
|
+
ResourceAttributes Map(LowCardinality(String), String) CODEC(ZSTD(1)),
|
|
264
|
+
ScopeName String CODEC(ZSTD(1)),
|
|
265
|
+
ScopeVersion String CODEC(ZSTD(1)),
|
|
266
|
+
SpanAttributes Map(LowCardinality(String), String) CODEC(ZSTD(1)),
|
|
267
|
+
Duration UInt64 CODEC(ZSTD(1)),
|
|
268
|
+
StatusCode LowCardinality(String) CODEC(ZSTD(1)),
|
|
269
|
+
StatusMessage String CODEC(ZSTD(1)),
|
|
270
|
+
Events Nested (
|
|
271
|
+
Timestamp DateTime64(9),
|
|
272
|
+
Name LowCardinality(String),
|
|
273
|
+
Attributes Map(LowCardinality(String), String)
|
|
274
|
+
) CODEC(ZSTD(1)),
|
|
275
|
+
Links Nested (
|
|
276
|
+
TraceId String,
|
|
277
|
+
SpanId String,
|
|
278
|
+
TraceState String,
|
|
279
|
+
Attributes Map(LowCardinality(String), String)
|
|
280
|
+
) CODEC(ZSTD(1)),
|
|
281
|
+
INDEX idx_trace_id TraceId TYPE bloom_filter(0.001) GRANULARITY 1,
|
|
282
|
+
INDEX idx_res_attr_key mapKeys(ResourceAttributes) TYPE bloom_filter(0.01) GRANULARITY 1,
|
|
283
|
+
INDEX idx_res_attr_value mapValues(ResourceAttributes) TYPE bloom_filter(0.01) GRANULARITY 1,
|
|
284
|
+
INDEX idx_span_attr_key mapKeys(SpanAttributes) TYPE bloom_filter(0.01) GRANULARITY 1,
|
|
285
|
+
INDEX idx_span_attr_value mapValues(SpanAttributes) TYPE bloom_filter(0.01) GRANULARITY 1,
|
|
286
|
+
INDEX idx_duration Duration TYPE minmax GRANULARITY 1
|
|
287
|
+
)
|
|
288
|
+
ENGINE = MergeTree
|
|
289
|
+
PARTITION BY toDate(Timestamp)
|
|
290
|
+
ORDER BY (ServiceName, SpanName, toDateTime(Timestamp))
|
|
291
|
+
${ttl("toDateTime(Timestamp)")}
|
|
292
|
+
SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1`;
|
|
293
|
+
|
|
294
|
+
const metric = (name: string, body: string) => table`
|
|
295
|
+
CREATE TABLE ${q(name)} (${METRIC_HEAD}${body}${METRIC_INDEXES}
|
|
296
|
+
)
|
|
297
|
+
ENGINE = MergeTree
|
|
298
|
+
PARTITION BY toDate(TimeUnix)
|
|
299
|
+
ORDER BY (ServiceName, MetricName, Attributes, toUnixTimestamp64Nano(TimeUnix))
|
|
300
|
+
${ttl("toDateTime(TimeUnix)")}
|
|
301
|
+
SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1`;
|
|
302
|
+
|
|
303
|
+
const members: OtelTablesMembers = {
|
|
304
|
+
logs,
|
|
305
|
+
traces,
|
|
306
|
+
metricsGauge: metric(names.gauge, METRIC_BODIES.gauge),
|
|
307
|
+
metricsSum: metric(names.sum, METRIC_BODIES.sum),
|
|
308
|
+
metricsSummary: metric(names.summary, METRIC_BODIES.summary),
|
|
309
|
+
metricsHistogram: metric(names.histogram, METRIC_BODIES.histogram),
|
|
310
|
+
metricsExponentialHistogram: metric(names.exponentialHistogram, METRIC_BODIES.exponentialHistogram),
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
if (props.traceIdLookup !== false) {
|
|
314
|
+
const traceIdTs = table`
|
|
315
|
+
CREATE TABLE ${q(`${names.traces}_trace_id_ts`)} (
|
|
316
|
+
TraceId String CODEC(ZSTD(1)),
|
|
317
|
+
Start DateTime CODEC(Delta, ZSTD(1)),
|
|
318
|
+
End DateTime CODEC(Delta, ZSTD(1)),
|
|
319
|
+
INDEX idx_trace_id TraceId TYPE bloom_filter(0.01) GRANULARITY 1
|
|
320
|
+
)
|
|
321
|
+
ENGINE = MergeTree
|
|
322
|
+
PARTITION BY toDate(Start)
|
|
323
|
+
ORDER BY (TraceId, Start)
|
|
324
|
+
${ttl("toDateTime(Start)")}
|
|
325
|
+
SETTINGS index_granularity = 8192, ttl_only_drop_parts = 1`;
|
|
326
|
+
const traceIdTsView = view`
|
|
327
|
+
CREATE MATERIALIZED VIEW ${q(`${names.traces}_trace_id_ts_mv`)} TO ${traceIdTs} AS
|
|
328
|
+
SELECT
|
|
329
|
+
TraceId,
|
|
330
|
+
min(Timestamp) AS Start,
|
|
331
|
+
max(Timestamp) AS End
|
|
332
|
+
FROM ${traces}
|
|
333
|
+
WHERE TraceId != ''
|
|
334
|
+
GROUP BY TraceId`;
|
|
335
|
+
members.traceIdTs = traceIdTs;
|
|
336
|
+
members.traceIdTsView = traceIdTsView;
|
|
337
|
+
}
|
|
338
|
+
return members;
|
|
339
|
+
}, "OtelTables");
|