Skip to content

Commit cb5eb7f

Browse files
committed
change example project start year to fit in doris partition history constraint. change doris docker to 1fe3be
1 parent 35916d7 commit cb5eb7f

File tree

5 files changed

+113
-40
lines changed

5 files changed

+113
-40
lines changed

sqlmesh/cli/project_init.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from sqlmesh.integrations.dlt import generate_dlt_models_and_settings
88
from sqlmesh.utils.date import yesterday_ds
99
from sqlmesh.utils.errors import SQLMeshError
10+
from datetime import datetime
1011

1112
from sqlmesh.core.config.connection import (
1213
CONNECTION_CONFIG_TO_TYPE,
@@ -160,7 +161,7 @@ class ExampleObjects:
160161
python_macros: t.Dict[str, str]
161162

162163

163-
def _gen_example_objects(schema_name: str) -> ExampleObjects:
164+
def _gen_example_objects(schema_name: str, start_year: int) -> ExampleObjects:
164165
sql_models: t.Dict[str, str] = {}
165166
python_models: t.Dict[str, str] = {}
166167
seeds: t.Dict[str, str] = {}
@@ -194,7 +195,7 @@ def _gen_example_objects(schema_name: str) -> ExampleObjects:
194195
kind INCREMENTAL_BY_TIME_RANGE (
195196
time_column event_date
196197
),
197-
start '2020-01-01',
198+
start '{start_year}-01-01',
198199
cron '@daily',
199200
grain (id, event_date)
200201
);
@@ -223,14 +224,14 @@ def _gen_example_objects(schema_name: str) -> ExampleObjects:
223224
);
224225
"""
225226

226-
seeds["seed_data"] = """id,item_id,event_date
227-
1,2,2020-01-01
228-
2,1,2020-01-01
229-
3,3,2020-01-03
230-
4,1,2020-01-04
231-
5,1,2020-01-05
232-
6,1,2020-01-06
233-
7,1,2020-01-07
227+
seeds["seed_data"] = f"""id,item_id,event_date
228+
1,2,{start_year}-01-01
229+
2,1,{start_year}-01-01
230+
3,3,{start_year}-01-03
231+
4,1,{start_year}-01-04
232+
5,1,{start_year}-01-05
233+
6,1,{start_year}-01-06
234+
7,1,{start_year}-01-07
234235
"""
235236

236237
audits["assert_positive_order_ids"] = """AUDIT (
@@ -328,6 +329,9 @@ def init_example_project(
328329
"Please provide a DLT pipeline with the `--dlt-pipeline` flag to generate a SQLMesh project from DLT."
329330
)
330331

332+
if engine_type == "doris":
333+
start = datetime(datetime.now().year, 1, 1).strftime("%Y-%m-%d")
334+
331335
_create_config(config_path, engine_type, dialect, settings, start, template, cli_mode)
332336
if template == ProjectTemplate.DBT:
333337
return config_path
@@ -340,7 +344,7 @@ def init_example_project(
340344
)
341345
return config_path
342346

343-
example_objects = _gen_example_objects(schema_name=schema_name)
347+
example_objects = _gen_example_objects(schema_name=schema_name, start_year=datetime.now().year)
344348

345349
if template != ProjectTemplate.EMPTY:
346350
_create_object_files(models_path, example_objects.sql_models, "sql")

sqlmesh/core/config/connection.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
"trino",
5151
# Nullable types are problematic
5252
"clickhouse",
53+
# Do not support table name starts with "_"
54+
"doris",
5355
}
5456
MOTHERDUCK_TOKEN_REGEX = re.compile(r"(\?|\&)(motherduck_token=)(\S*)")
5557

sqlmesh/core/engine_adapter/doris.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -649,16 +649,6 @@ def _create_table_from_columns(
649649
"""
650650
table_properties = kwargs.get("table_properties", {})
651651

652-
# Set default replication_num to 1 for testing environments if not specified
653-
if (
654-
"replication_num" not in table_properties
655-
and "replication_allocation" not in table_properties
656-
):
657-
table_properties["replication_num"] = "1"
658-
logger.info(
659-
f"[Doris] Added default replication_num for testing: {table_properties['replication_num']}"
660-
)
661-
662652
# Convert primary_key to unique_key for Doris (Doris doesn't support primary keys)
663653
if primary_key and "unique_key" not in table_properties:
664654
table_properties["unique_key"] = primary_key
@@ -688,7 +678,6 @@ def _build_partitioned_by_exp(
688678
) -> t.Optional[t.Union[exp.PartitionedByProperty, exp.PartitionByRangeProperty, exp.Property]]:
689679
"""Doris supports range and list partition, but sqlglot only supports range partition, so we use PartitionByRangeProperty."""
690680
# Handle partitioned_by_expr from kwargs
691-
logging.info(f"[Doris] _build_partitioned_by_exp called with kwargs: {kwargs}")
692681
partitioned_by_expr = kwargs.get("partitioned_by_expr")
693682
create_expressions = None
694683

@@ -861,18 +850,20 @@ def _build_table_properties_exp(
861850
dynamic_partition_props = {
862851
"dynamic_partition.enable": "true",
863852
"dynamic_partition.time_unit": "DAY",
864-
"dynamic_partition.history_partition_num": "400",
865-
"dynamic_partition.end": "7",
853+
"dynamic_partition.start": "-490",
854+
"dynamic_partition.end": "10",
866855
"dynamic_partition.prefix": "p",
867856
"dynamic_partition.buckets": "32",
868857
"dynamic_partition.create_history_partition": "true",
869858
}
870859

871860
# Use partition_interval_unit if provided to set the time_unit
872861
if partition_interval_unit:
873-
dynamic_partition_props["dynamic_partition.time_unit"] = (
874-
partition_interval_unit.upper()
875-
)
862+
if hasattr(partition_interval_unit, "value"):
863+
time_unit = partition_interval_unit.value.upper()
864+
else:
865+
time_unit = str(partition_interval_unit).upper()
866+
dynamic_partition_props["dynamic_partition.time_unit"] = time_unit
876867

877868
# Add missing dynamic partition properties to table_properties_copy
878869
for key, value in dynamic_partition_props.items():

sqlmesh/core/model/meta.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,22 @@ def batch_concurrency(self) -> t.Optional[int]:
464464
@cached_property
465465
def physical_properties(self) -> t.Dict[str, exp.Expression]:
466466
"""A dictionary of properties that will be applied to the physical layer. It replaces table_properties which is deprecated."""
467+
properties = {}
467468
if self.physical_properties_:
468-
return {e.this.name: e.expression for e in self.physical_properties_.expressions}
469-
return {}
469+
properties = {e.this.name: e.expression for e in self.physical_properties_.expressions}
470+
471+
# For INCREMENTAL_BY_UNIQUE_KEY models, add the unique_key to physical_properties
472+
# so it gets passed to table_properties during table creation
473+
if isinstance(self.kind, IncrementalByUniqueKeyKind) and self.unique_key:
474+
# Convert unique_key expressions to a format suitable for table_properties
475+
if len(self.unique_key) == 1:
476+
# Single column key
477+
properties["unique_key"] = self.unique_key[0]
478+
else:
479+
# Multiple column key - create a tuple expression
480+
properties["unique_key"] = exp.Tuple(expressions=self.unique_key)
481+
482+
return properties
470483

471484
@cached_property
472485
def virtual_properties(self) -> t.Dict[str, exp.Expression]:
Lines changed: 74 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,80 @@
11
services:
2-
fe:
2+
fe-01:
33
image: apache/doris:fe-2.1.10
4-
hostname: fe
4+
container_name: doris-fe-01
5+
hostname: fe-01
56
environment:
6-
- FE_SERVERS=fe1:127.0.0.1:9010
7-
- FE_ID=1
8-
network_mode: host
9-
be:
7+
- FE_SERVERS=fe1:172.20.80.2:9030
8+
- FE_ID=1
9+
ports:
10+
- "8030:8030"
11+
- "9030:9030"
12+
volumes:
13+
- ./fe-meta:/opt/apache-doris/fe/doris-meta
14+
- ./fe-log:/opt/apache-doris/fe/log
15+
networks:
16+
doris_net:
17+
ipv4_address: 172.20.80.2
18+
19+
be-01:
1020
image: apache/doris:be-2.1.10
11-
hostname: be
21+
container_name: doris-be-01
22+
hostname: be-01
23+
depends_on:
24+
- fe-01
25+
environment:
26+
- FE_SERVERS=fe1:172.20.80.2:9030
27+
- BE_ADDR=172.20.80.3:9050
28+
ports:
29+
- "8040:8040"
30+
- "9050:9050"
31+
volumes:
32+
- ./be01-storage:/opt/apache-doris/be/storage
33+
- ./be01-log:/opt/apache-doris/be/log
34+
networks:
35+
doris_net:
36+
ipv4_address: 172.20.80.3
37+
38+
be-02:
39+
image: apache/doris:be-2.1.10
40+
container_name: doris-be-02
41+
hostname: be-02
42+
depends_on:
43+
- fe-01
1244
environment:
13-
- FE_SERVERS=fe1:127.0.0.1:9010
14-
- BE_ADDR=127.0.0.1:9050
45+
- FE_SERVERS=fe1:172.20.80.2:9030
46+
- BE_ADDR=172.20.80.4:9050
47+
ports:
48+
- "8041:8040"
49+
- "9051:9050"
50+
volumes:
51+
- ./be02-storage:/opt/apache-doris/be/storage
52+
- ./be02-log:/opt/apache-doris/be/log
53+
networks:
54+
doris_net:
55+
ipv4_address: 172.20.80.4
56+
57+
be-03:
58+
image: apache/doris:be-2.1.10
59+
container_name: doris-be-03
60+
hostname: be-03
1561
depends_on:
16-
- fe
17-
network_mode: host
62+
- fe-01
63+
environment:
64+
- FE_SERVERS=fe1:172.20.80.2:9030
65+
- BE_ADDR=172.20.80.5:9050
66+
ports:
67+
- "8042:8040"
68+
- "9052:9050"
69+
volumes:
70+
- ./be03-storage:/opt/apache-doris/be/storage
71+
- ./be03-log:/opt/apache-doris/be/log
72+
networks:
73+
doris_net:
74+
ipv4_address: 172.20.80.5
75+
76+
networks:
77+
doris_net:
78+
ipam:
79+
config:
80+
- subnet: 172.20.80.0/24

0 commit comments

Comments
 (0)