clickzetta-semantic-model-generator 1.0.0__tar.gz

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.
Files changed (35) hide show
  1. clickzetta_semantic_model_generator-1.0.0/LICENSE +201 -0
  2. clickzetta_semantic_model_generator-1.0.0/PKG-INFO +185 -0
  3. clickzetta_semantic_model_generator-1.0.0/README.md +148 -0
  4. clickzetta_semantic_model_generator-1.0.0/pyproject.toml +51 -0
  5. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/__init__.py +0 -0
  6. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/clickzetta_utils/clickzetta_connector.py +984 -0
  7. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/clickzetta_utils/env_vars.py +233 -0
  8. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/clickzetta_utils/utils.py +144 -0
  9. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/data_processing/__init__.py +0 -0
  10. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/data_processing/cte_utils.py +415 -0
  11. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/data_processing/cte_utils_test.py +70 -0
  12. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/data_processing/data_types.py +48 -0
  13. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/data_processing/proto_utils.py +87 -0
  14. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/generate_model.py +2976 -0
  15. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/llm/__init__.py +36 -0
  16. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/llm/dashscope_client.py +163 -0
  17. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/llm/enrichment.py +1110 -0
  18. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/llm/progress_tracker.py +198 -0
  19. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/output_models/.keep +0 -0
  20. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/protos/semantic_model.proto +389 -0
  21. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/protos/semantic_model_pb2.py +228 -0
  22. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/protos/semantic_model_pb2.pyi +352 -0
  23. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/tests/clickzetta_connector_test.py +92 -0
  24. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/tests/cte_utils_test.py +476 -0
  25. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/tests/generate_model_classification_test.py +58 -0
  26. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/tests/llm_enrichment_test.py +423 -0
  27. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/tests/relationships_filters_test.py +225 -0
  28. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/tests/samples/validate_yamls.py +444 -0
  29. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/tests/utils_test.py +20 -0
  30. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/tests/validate_model_test.py +14 -0
  31. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/tests/yaml_to_semantic_model_test.py +93 -0
  32. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/validate/context_length.py +107 -0
  33. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/validate/keywords.py +57 -0
  34. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/validate/schema.py +163 -0
  35. clickzetta_semantic_model_generator-1.0.0/semantic_model_generator/validate_model.py +28 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,185 @@
1
+ Metadata-Version: 2.3
2
+ Name: clickzetta-semantic-model-generator
3
+ Version: 1.0.0
4
+ Summary: Curate a Semantic Model for ClickZetta Lakehouse
5
+ License: Apache Software License; BSD License
6
+ Author: qililiang
7
+ Author-email: qililiang@clickzetta.com
8
+ Requires-Python: >=3.9, !=2.7.*, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, !=3.6.*, !=3.7.*, !=3.8.*, !=3.12.*, !=3.13.*
9
+ Classifier: License :: Other/Proprietary License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.9
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Provides-Extra: looker
15
+ Requires-Dist: PyYAML (>=6.0.1,<7.0.0)
16
+ Requires-Dist: clickzetta-connector-python (==0.8.92)
17
+ Requires-Dist: clickzetta-zettapark-python (==0.1.3)
18
+ Requires-Dist: dashscope (>=1.22.2,<2.0.0)
19
+ Requires-Dist: loguru (>=0.7.2,<0.8.0)
20
+ Requires-Dist: looker-sdk (>=24.14.0,<25.0.0) ; extra == "looker"
21
+ Requires-Dist: numpy (>=1.26.4,<2.0.0)
22
+ Requires-Dist: pandas (>=2.0.1,<3.0.0)
23
+ Requires-Dist: protobuf (==5.26.1)
24
+ Requires-Dist: pyarrow (==14.0.2)
25
+ Requires-Dist: pydantic (==2.8.2)
26
+ Requires-Dist: python-dotenv (>=1.0.1,<2.0.0)
27
+ Requires-Dist: requests (>=2.32.3,<3.0.0)
28
+ Requires-Dist: ruamel.yaml (==0.17.21)
29
+ Requires-Dist: sqlglot (==25.10.0)
30
+ Requires-Dist: streamlit (==1.36.0)
31
+ Requires-Dist: streamlit-extras (==0.4.0)
32
+ Requires-Dist: strictyaml (>=1.7.3,<2.0.0)
33
+ Requires-Dist: tqdm (>=4.66.5,<5.0.0)
34
+ Requires-Dist: urllib3 (>=1.26.19,<2.0.0)
35
+ Description-Content-Type: text/markdown
36
+
37
+ # semantic-model-generator
38
+
39
+ The ClickZetta Semantic Model Generator is a Streamlit companion built for ClickZetta teams. Use it to explore Lakehouse metadata, author and refine semantic YAML, and plug into partner workflows—everything runs against ClickZetta’s Lakehouse APIs and backed volumes by default.
40
+
41
+ ## Requirements
42
+
43
+ - Python 3.11
44
+ - Access to a ClickZetta workspace (service URL, instance, workspace, schema, vcluster, username, password)
45
+ - A `connections.json` file in one of the standard ClickZetta locations (`~/.clickzetta/connections.json`, `config/connections.json`, `config/lakehouse_connection/connections.json`, or `/app/.clickzetta/lakehouse_connection/connections.json`). The structure matches the template from [`mcp-clickzetta-server`](https://github.com/yunqiqiliang/mcp-clickzetta-server/blob/main/config/connections-template.json). Set "is_default": true for the connection the app should use.
46
+
47
+ ```json
48
+ {
49
+ "system_config": {
50
+ "embedding": {
51
+ "provider": "dashscope",
52
+ "dashscope": {
53
+ "api_key": "dashscope_api_key",
54
+ "model": "qwen-plus-latest"
55
+ }
56
+ }
57
+ },
58
+ "connections": [
59
+ {
60
+ "connection_name": "dev",
61
+ "is_default": true,
62
+ "service": "cn-shanghai-alicloud.api.clickzetta.com",
63
+ "instance": "your_instance",
64
+ "workspace": "quick_start",
65
+ "schema": "PUBLIC",
66
+ "username": "user",
67
+ "password": "password",
68
+ "vcluster": "default_ap"
69
+ }
70
+ ]
71
+ }
72
+ ```
73
+
74
+ Environment variables such as `CLICKZETTA_SERVICE`, `CLICKZETTA_USERNAME`, etc. override the JSON values when present.
75
+
76
+ ## App Overview
77
+
78
+ The Streamlit homepage highlights how to use this toolkit alongside the ClickZetta platform:
79
+
80
+ - **Local companion for semantic modeling.** Iterate quickly on YAML, inspect metadata, and validate changes before promoting them back to your Lakehouse.
81
+ - **Keep production work in ClickZetta.** Build and manage canonical models in the ClickZetta console, then switch to this app when you need richer editing, partner integrations, or AI enrichment—both share the same volumes for frictionless workflows.
82
+ - **Why semantics matter.** A curated semantic layer standardizes measures, joins, and business logic so LLMs understand context, avoid hallucinations, and deliver consistent analytics for data teams and business users.
83
+ - **Typical workflows covered:** author and refine models from table metadata, safely edit existing YAML with ClickZetta validation, generate/test SQL through the chat assistant, and auto-enrich documentation via DashScope.
84
+ - **Use it as a sandbox.** Pull models from a volume, experiment with the editor and chat assistant, then push the refined YAML back once it passes validation.
85
+
86
+ ![Semantic model generator architecture](images/semantic-model-overview.svg)
87
+
88
+ ## Installation from Docker
89
+
90
+ If you prefer not to install Python dependencies locally, pull the published Docker image:
91
+
92
+ ```bash
93
+ docker pull czqiliang/semantic-model-generator:latest
94
+ docker run --rm -p 8501:8501 \
95
+ -v $(pwd)/connections.json:/app/.clickzetta/connections.json \
96
+ czqiliang/semantic-model-generator:latest
97
+ ```
98
+
99
+ Mount your `connections.json` (see example below) so the container can pick up ClickZetta and DashScope credentials.
100
+
101
+ The Streamlit UI will be available at http://localhost:8501.
102
+
103
+ Docker Compose example (`docker-compose.yml`):
104
+
105
+ ```yaml
106
+ version: "3.9"
107
+ services:
108
+ app:
109
+ image: czqiliang/semantic-model-generator:latest
110
+ ports:
111
+ - "8501:8501"
112
+ volumes:
113
+ - ~/.clickzetta:/app/.clickzetta # macOS 默认配置挂载
114
+ ```
115
+
116
+ Run it with `docker compose up`.
117
+
118
+ Linux 主机通常会把 ClickZetta 配置放在 `/opt/clickzetta` 下,Compose 配置可以改成:
119
+
120
+ ```yaml
121
+ volumes:
122
+ - /opt/clickzetta:/app/.clickzetta
123
+ ```
124
+
125
+ ## or Installation from source code
126
+
127
+ ```bash
128
+ # optional: conda env using environment.yml
129
+ conda env create -f environment.yml
130
+ conda activate clickzetta_env
131
+
132
+ # or install via poetry/pip
133
+ poetry install
134
+ # pip install .
135
+ ```
136
+
137
+ The app depends on `clickzetta-connector-python` and `clickzetta-zettapark-python`; ensure they are installed via the commands above.
138
+
139
+ ## Running the Streamlit app
140
+
141
+ ```bash
142
+ # inside the Poetry environment
143
+ poetry run streamlit run app.py
144
+
145
+ # or, after activating the env, run:
146
+ python -m streamlit run app.py
147
+ ```
148
+
149
+ When the app launches it will:
150
+
151
+ 1. Load credentials from the ClickZetta connection config or environment.
152
+ 2. Default file operations to `volume:user://~/semantic_models/` inside your user volume.
153
+ 3. Provide workflows for generating semantic YAML, editing YAML, validating (basic checks), and importing partner specs (dbt, etc.).
154
+
155
+ ## DashScope 使用提示
156
+
157
+ - 语义补全调用 DashScope 官方 SDK 默认端点,无需也无法通过 `base_url` 重写。
158
+ - 即便在 `connections.json` 或环境变量里设置 `DASHSCOPE_BASE_URL`/兼容端点,应用也不会使用这些值。
159
+ - 仍需提供 `DASHSCOPE_API_KEY` 与模型名称(如 `qwen-plus`);其他参数保持默认即可避免常见 `InvalidParameter: url error`。
160
+ - 仅当你明确需要 OpenAI 兼容模式时才应使用兼容端点;当前 Streamlit 应用未对兼容端点提供支持。
161
+
162
+ ## Key behaviours
163
+
164
+ - **Volume-first uploads**: YAML import/export uses the user volume path `volume:user://~/semantic_models/` unless a different volume/stage is selected.
165
+ - **Metadata discovery**: Workspace metadata (catalogs, schemas, tables) is fetched via ClickZetta INFORMATION_SCHEMA queries. Sample values and comments are collected using ClickZetta sessions.
166
+ - **Partner integrations**: dbt helpers read YAML from the chosen volume/stage, merge metadata, and reuse ClickZetta credentials.
167
+ - **Chat/validation placeholders**: Cortex-specific validation and chat calls are not yet available in ClickZetta mode; the UI will display placeholders instead of calling external services.
168
+
169
+ ## Development scripts
170
+
171
+ Useful commands while iterating:
172
+
173
+ ```bash
174
+ make setup # install dependencies
175
+ make run_admin_app
176
+ make fmt_lint # format + lint
177
+ make test # execute pytest suite
178
+ make docker-buildx # build multi-arch Docker image (linux/amd64, linux/arm64)
179
+ make docker-buildx-push # build and push multi-arch image
180
+ ```
181
+
182
+ ## License
183
+
184
+ Apache 2.0 / BSD (dual license) – see LICENSE and LEGAL files for details.
185
+
@@ -0,0 +1,148 @@
1
+ # semantic-model-generator
2
+
3
+ The ClickZetta Semantic Model Generator is a Streamlit companion built for ClickZetta teams. Use it to explore Lakehouse metadata, author and refine semantic YAML, and plug into partner workflows—everything runs against ClickZetta’s Lakehouse APIs and backed volumes by default.
4
+
5
+ ## Requirements
6
+
7
+ - Python 3.11
8
+ - Access to a ClickZetta workspace (service URL, instance, workspace, schema, vcluster, username, password)
9
+ - A `connections.json` file in one of the standard ClickZetta locations (`~/.clickzetta/connections.json`, `config/connections.json`, `config/lakehouse_connection/connections.json`, or `/app/.clickzetta/lakehouse_connection/connections.json`). The structure matches the template from [`mcp-clickzetta-server`](https://github.com/yunqiqiliang/mcp-clickzetta-server/blob/main/config/connections-template.json). Set "is_default": true for the connection the app should use.
10
+
11
+ ```json
12
+ {
13
+ "system_config": {
14
+ "embedding": {
15
+ "provider": "dashscope",
16
+ "dashscope": {
17
+ "api_key": "dashscope_api_key",
18
+ "model": "qwen-plus-latest"
19
+ }
20
+ }
21
+ },
22
+ "connections": [
23
+ {
24
+ "connection_name": "dev",
25
+ "is_default": true,
26
+ "service": "cn-shanghai-alicloud.api.clickzetta.com",
27
+ "instance": "your_instance",
28
+ "workspace": "quick_start",
29
+ "schema": "PUBLIC",
30
+ "username": "user",
31
+ "password": "password",
32
+ "vcluster": "default_ap"
33
+ }
34
+ ]
35
+ }
36
+ ```
37
+
38
+ Environment variables such as `CLICKZETTA_SERVICE`, `CLICKZETTA_USERNAME`, etc. override the JSON values when present.
39
+
40
+ ## App Overview
41
+
42
+ The Streamlit homepage highlights how to use this toolkit alongside the ClickZetta platform:
43
+
44
+ - **Local companion for semantic modeling.** Iterate quickly on YAML, inspect metadata, and validate changes before promoting them back to your Lakehouse.
45
+ - **Keep production work in ClickZetta.** Build and manage canonical models in the ClickZetta console, then switch to this app when you need richer editing, partner integrations, or AI enrichment—both share the same volumes for frictionless workflows.
46
+ - **Why semantics matter.** A curated semantic layer standardizes measures, joins, and business logic so LLMs understand context, avoid hallucinations, and deliver consistent analytics for data teams and business users.
47
+ - **Typical workflows covered:** author and refine models from table metadata, safely edit existing YAML with ClickZetta validation, generate/test SQL through the chat assistant, and auto-enrich documentation via DashScope.
48
+ - **Use it as a sandbox.** Pull models from a volume, experiment with the editor and chat assistant, then push the refined YAML back once it passes validation.
49
+
50
+ ![Semantic model generator architecture](images/semantic-model-overview.svg)
51
+
52
+ ## Installation from Docker
53
+
54
+ If you prefer not to install Python dependencies locally, pull the published Docker image:
55
+
56
+ ```bash
57
+ docker pull czqiliang/semantic-model-generator:latest
58
+ docker run --rm -p 8501:8501 \
59
+ -v $(pwd)/connections.json:/app/.clickzetta/connections.json \
60
+ czqiliang/semantic-model-generator:latest
61
+ ```
62
+
63
+ Mount your `connections.json` (see example below) so the container can pick up ClickZetta and DashScope credentials.
64
+
65
+ The Streamlit UI will be available at http://localhost:8501.
66
+
67
+ Docker Compose example (`docker-compose.yml`):
68
+
69
+ ```yaml
70
+ version: "3.9"
71
+ services:
72
+ app:
73
+ image: czqiliang/semantic-model-generator:latest
74
+ ports:
75
+ - "8501:8501"
76
+ volumes:
77
+ - ~/.clickzetta:/app/.clickzetta # macOS 默认配置挂载
78
+ ```
79
+
80
+ Run it with `docker compose up`.
81
+
82
+ Linux 主机通常会把 ClickZetta 配置放在 `/opt/clickzetta` 下,Compose 配置可以改成:
83
+
84
+ ```yaml
85
+ volumes:
86
+ - /opt/clickzetta:/app/.clickzetta
87
+ ```
88
+
89
+ ## or Installation from source code
90
+
91
+ ```bash
92
+ # optional: conda env using environment.yml
93
+ conda env create -f environment.yml
94
+ conda activate clickzetta_env
95
+
96
+ # or install via poetry/pip
97
+ poetry install
98
+ # pip install .
99
+ ```
100
+
101
+ The app depends on `clickzetta-connector-python` and `clickzetta-zettapark-python`; ensure they are installed via the commands above.
102
+
103
+ ## Running the Streamlit app
104
+
105
+ ```bash
106
+ # inside the Poetry environment
107
+ poetry run streamlit run app.py
108
+
109
+ # or, after activating the env, run:
110
+ python -m streamlit run app.py
111
+ ```
112
+
113
+ When the app launches it will:
114
+
115
+ 1. Load credentials from the ClickZetta connection config or environment.
116
+ 2. Default file operations to `volume:user://~/semantic_models/` inside your user volume.
117
+ 3. Provide workflows for generating semantic YAML, editing YAML, validating (basic checks), and importing partner specs (dbt, etc.).
118
+
119
+ ## DashScope 使用提示
120
+
121
+ - 语义补全调用 DashScope 官方 SDK 默认端点,无需也无法通过 `base_url` 重写。
122
+ - 即便在 `connections.json` 或环境变量里设置 `DASHSCOPE_BASE_URL`/兼容端点,应用也不会使用这些值。
123
+ - 仍需提供 `DASHSCOPE_API_KEY` 与模型名称(如 `qwen-plus`);其他参数保持默认即可避免常见 `InvalidParameter: url error`。
124
+ - 仅当你明确需要 OpenAI 兼容模式时才应使用兼容端点;当前 Streamlit 应用未对兼容端点提供支持。
125
+
126
+ ## Key behaviours
127
+
128
+ - **Volume-first uploads**: YAML import/export uses the user volume path `volume:user://~/semantic_models/` unless a different volume/stage is selected.
129
+ - **Metadata discovery**: Workspace metadata (catalogs, schemas, tables) is fetched via ClickZetta INFORMATION_SCHEMA queries. Sample values and comments are collected using ClickZetta sessions.
130
+ - **Partner integrations**: dbt helpers read YAML from the chosen volume/stage, merge metadata, and reuse ClickZetta credentials.
131
+ - **Chat/validation placeholders**: Cortex-specific validation and chat calls are not yet available in ClickZetta mode; the UI will display placeholders instead of calling external services.
132
+
133
+ ## Development scripts
134
+
135
+ Useful commands while iterating:
136
+
137
+ ```bash
138
+ make setup # install dependencies
139
+ make run_admin_app
140
+ make fmt_lint # format + lint
141
+ make test # execute pytest suite
142
+ make docker-buildx # build multi-arch Docker image (linux/amd64, linux/arm64)
143
+ make docker-buildx-push # build and push multi-arch image
144
+ ```
145
+
146
+ ## License
147
+
148
+ Apache 2.0 / BSD (dual license) – see LICENSE and LEGAL files for details.
@@ -0,0 +1,51 @@
1
+ [tool.poetry]
2
+ name = "clickzetta-semantic-model-generator"
3
+ version = "1.0.0"
4
+ description = "Curate a Semantic Model for ClickZetta Lakehouse"
5
+ authors = ["qililiang <qililiang@clickzetta.com>"]
6
+ license = "Apache Software License; BSD License"
7
+ readme = "README.md"
8
+ packages = [{include = "semantic_model_generator"}]
9
+
10
+ [tool.poetry.dependencies]
11
+ python = ">=3.9,<3.9.7 || >3.9.7,<3.12"
12
+ pandas = "^2.0.1"
13
+ loguru = "^0.7.2"
14
+ clickzetta-connector-python = "0.8.92"
15
+ protobuf = "5.26.1"
16
+ pydantic = "2.8.2"
17
+ PyYAML = "^6.0.1"
18
+ "ruamel.yaml" = "0.17.21"
19
+ tqdm = "^4.66.5"
20
+ pyarrow = "14.0.2"
21
+ sqlglot = "25.10.0"
22
+ strictyaml = "^1.7.3"
23
+ streamlit = "1.36.0"
24
+ streamlit-extras = "0.4.0"
25
+ numpy = "^1.26.4"
26
+ python-dotenv = "^1.0.1"
27
+ urllib3 = "^1.26.19"
28
+ requests = "^2.32.3"
29
+ clickzetta-zettapark-python = "0.1.3"
30
+ dashscope = "^1.22.2"
31
+
32
+ # Optional dependencies for functionality such as partner semantic model support.
33
+ looker-sdk = { version = "^24.14.0", optional = true }
34
+
35
+ [tool.poetry.group.dev.dependencies]
36
+ mypy = "^1.9.0"
37
+ black = "^24.3.0"
38
+ isort = "^5.13.2"
39
+ flake8 = "^7.0.0"
40
+ pytest = "^8.1.1"
41
+ types-pyyaml = "^6.0.12.20240311"
42
+ types-protobuf = "^4.24.0.20240311"
43
+ pip-licenses = "^4.4.0"
44
+ grpcio-tools = "1.64.1"
45
+
46
+ [tool.poetry.extras]
47
+ looker = ["looker-sdk"]
48
+
49
+ [build-system]
50
+ requires = ["poetry-core"]
51
+ build-backend = "poetry.core.masonry.api"