bombsimon commented on code in PR #2009:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2009#discussion_r2290535129
##########
tests/sqlparser_snowflake.rs:
##########
@@ -4581,3 +4581,129 @@ fn test_drop_constraints() {
snowflake().verified_stmt("ALTER TABLE tbl DROP FOREIGN KEY k1 RESTRICT");
snowflake().verified_stmt("ALTER TABLE tbl DROP CONSTRAINT c1 CASCADE");
}
+
+#[test]
+fn test_semantic_view_all_variants_should_pass() {
+ let test_cases = [
+ ("SELECT * FROM SEMANTIC_VIEW(model)", None),
+ (
+ "SELECT * FROM SEMANTIC_VIEW(model DIMENSIONS dim1, dim2)",
+ None,
+ ),
+ (
+ "SELECT * FROM SEMANTIC_VIEW(model METRICS met1, met2)",
+ None,
+ ),
+ (
+ "SELECT * FROM SEMANTIC_VIEW(model FACTS fact1, fact2)",
+ None,
+ ),
+ (
+ "SELECT * FROM SEMANTIC_VIEW(model DIMENSIONS dim1 METRICS met1)",
+ None,
+ ),
+ (
+ "SELECT * FROM SEMANTIC_VIEW(model DIMENSIONS dim1 WHERE x > 0)",
+ None,
+ ),
+ (
+ "SELECT * FROM SEMANTIC_VIEW(model DIMENSIONS dim1) AS sv",
+ None,
+ ),
+ (
+ "SELECT * FROM SEMANTIC_VIEW(model DIMENSIONS DATE_PART('year',
col))",
+ None,
+ ),
+ (
+ "SELECT * FROM SEMANTIC_VIEW(model METRICS orders.col,
orders.col2)",
+ None,
+ ),
+ // We can parse in any order bu will always produce a result in a
fixed order.
+ (
+ "SELECT * FROM SEMANTIC_VIEW(model WHERE x > 0 DIMENSIONS dim1)",
+ Some("SELECT * FROM SEMANTIC_VIEW(model DIMENSIONS dim1 WHERE x >
0)"),
+ ),
+ (
+ "SELECT * FROM SEMANTIC_VIEW(model METRICS met1 DIMENSIONS dim1)",
+ Some("SELECT * FROM SEMANTIC_VIEW(model DIMENSIONS dim1 METRICS
met1)"),
+ ),
+ (
+ "SELECT * FROM SEMANTIC_VIEW(model FACTS fact1 DIMENSIONS dim1)",
+ Some("SELECT * FROM SEMANTIC_VIEW(model DIMENSIONS dim1 FACTS
fact1)"),
+ ),
+ ];
+
+ for (input_sql, expected_sql) in test_cases {
+ if let Some(expected) = expected_sql {
+ // Test that non-canonical order gets normalized
+ let parsed = snowflake().parse_sql_statements(input_sql).unwrap();
+ let formatted = parsed[0].to_string();
+ assert_eq!(formatted, expected);
+ } else {
+ snowflake().verified_stmt(input_sql);
+ }
+ }
+}
+
+#[test]
+fn test_semantic_view_invalid_queries_should_fail() {
+ let invalid_sqls = [
+ "SELECT * FROM SEMANTIC_VIEW(model DIMENSIONS dim1 INVALID inv1)",
+ "SELECT * FROM SEMANTIC_VIEW(model DIMENSIONS dim1 DIMENSIONS dim2)",
+ "SELECT * FROM SEMANTIC_VIEW(model METRICS SUM(met1.avg))",
+ ];
+
+ for sql in invalid_sqls {
+ let result = snowflake().parse_sql_statements(sql);
+ assert!(result.is_err(), "Expected error for invalid SQL: {}", sql);
+ }
+}
+
+#[test]
+fn test_semantic_view_ast_structure() {
Review Comment:
I can change this, but I'm not sure I agree. I think there are three
different test scenarios and splitting them up makes the tests smaller and
easier to read, we seem to do this elsewhere. In fact, we even have things like
this 😅
https://github.com/apache/datafusion-sqlparser-rs/blob/cb7a51e85f434d10d5b3ac79cfb09533cca004f7/tests/sqlparser_snowflake.rs#L4400-L4419
If this is something you want to change going forward I can merge them but
my opinion is that keeping them separate is easier to read and maintain so my
personal preference is to keep it as is.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]