You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
=="Please add the required 'name' field to the MODEL block at the top of the file.\n\nLearn more at https://sqlmesh.readthedocs.io/en/stable/concepts/models/overview"
590
+
)
591
+
592
+
593
+
deftest_model_field_name_suggestions():
594
+
# top-level field
595
+
expressions=d.parse(
596
+
"""
597
+
MODEL (
598
+
name db.table,
599
+
dialects bigquery,
600
+
);
601
+
602
+
SELECT 1::int AS a, 2::int AS b;
603
+
"""
604
+
)
605
+
606
+
withpytest.raises(ConfigError) asex:
607
+
load_sql_based_model(expressions)
608
+
assert (
609
+
str(ex.value)
610
+
=="Invalid field name present in the MODEL block: 'dialects'. Did you mean 'dialect'?"
611
+
)
612
+
613
+
# kind field
614
+
expressions=d.parse(
615
+
"""
616
+
MODEL (
617
+
name db.table,
618
+
kind INCREMENTAL_BY_TIME_RANGE(
619
+
time_column a,
620
+
batch_sizes 1
621
+
),
622
+
);
623
+
624
+
SELECT 1::int AS a, 2::int AS b;
625
+
"""
626
+
)
627
+
628
+
withpytest.raises(ConfigError) asex:
629
+
load_sql_based_model(expressions)
630
+
assert (
631
+
str(ex.value)
632
+
=="Invalid field name present in the MODEL block 'kind INCREMENTAL_BY_TIME_RANGE' field: 'batch_sizes'. Did you mean 'batch_size'?"
633
+
)
634
+
635
+
# multiple fields
636
+
expressions=d.parse(
637
+
"""
638
+
MODEL (
639
+
name db.table,
640
+
dialects bigquery,
641
+
descriptions 'a',
642
+
asdfasdf true
643
+
);
644
+
645
+
SELECT 1::int AS a, 2::int AS b;
646
+
"""
647
+
)
648
+
649
+
withpytest.raises(ConfigError) asex:
650
+
load_sql_based_model(expressions)
651
+
ex_str=str(ex.value)
652
+
# field order is non-deterministic, so we can't test the output string directly
653
+
assert"Invalid field names present in the MODEL block: "inex_str
654
+
assert"'descriptions'"inex_str
655
+
assert"'dialects'"inex_str
656
+
assert"'asdfasdf'"inex_str
657
+
assert"- descriptions: Did you mean 'description'?"inex_str
658
+
assert"- dialects: Did you mean 'dialect'?"inex_str
659
+
assert"- asdfasdf: Did you mean "notinex_str
660
+
661
+
662
+
deftest_model_required_field_missing():
663
+
expressions=d.parse(
664
+
"""
665
+
MODEL (
666
+
name db.table,
667
+
kind INCREMENTAL_BY_TIME_RANGE (),
668
+
);
669
+
670
+
SELECT 1::int AS a, 2::int AS b;
671
+
"""
672
+
)
673
+
674
+
withpytest.raises(ConfigError) asex:
675
+
load_sql_based_model(expressions)
676
+
assert (
677
+
str(ex.value)
678
+
=="Please add required field 'time_column' to the MODEL block 'kind INCREMENTAL_BY_TIME_RANGE' field."
0 commit comments