Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions apps/framework-cli-e2e/test/utils/database-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ export interface ExpectedColumn {
nullable?: boolean;
comment?: string;
codec?: string | RegExp;
materialized?: string | RegExp;
}

/**
Expand Down Expand Up @@ -454,6 +455,32 @@ export const validateTableSchema = async (
);
}
}

// Materialized validation (if specified)
if (expectedCol.materialized !== undefined) {
const actualMaterialized = actualCol.default_expression;
const actualDefaultType = actualCol.default_type;
let materializedMatches = false;

// Check that it's actually a MATERIALIZED column
if (actualDefaultType === "MATERIALIZED") {
if (typeof expectedCol.materialized === "string") {
// Exact string match
materializedMatches =
actualMaterialized === expectedCol.materialized;
} else if (expectedCol.materialized instanceof RegExp) {
// Regex match for complex expressions
materializedMatches =
expectedCol.materialized.test(actualMaterialized);
}
}

if (!materializedMatches) {
errors.push(
`Column '${expectedCol.name}' materialized mismatch: expected '${expectedCol.materialized}', got '${actualDefaultType === "MATERIALIZED" ? actualMaterialized : "(not materialized)"}'`,
);
}
}
}

// Check for unexpected columns (optional - could be made configurable)
Expand Down
50 changes: 50 additions & 0 deletions apps/framework-cli-e2e/test/utils/schema-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,29 @@ export const TYPESCRIPT_TEST_SCHEMAS: ExpectedTableSchema[] = [
{ name: "status_code", type: "Float64" },
],
},
// Materialized column test table
{
tableName: "MaterializedTest",
columns: [
{ name: "id", type: "String" },
{ name: "timestamp", type: /DateTime\('UTC'\)/ },
{ name: "userId", type: "String" },
{
name: "eventDate",
type: /Date(32)?/,
materialized: "toDate(timestamp)",
},
{ name: "userHash", type: "UInt64", materialized: "cityHash64(userId)" },
{ name: "log_blob", type: "JSON", codec: "ZSTD(3)" },
{
name: "combinationHash",
type: "Array(UInt64)",
materialized:
"arrayMap(kv -> cityHash64(kv.1, kv.2), JSONExtractKeysAndValuesRaw(toString(log_blob)))",
codec: "ZSTD(1)",
},
],
},
];

// ============ PYTHON TEMPLATE SCHEMA DEFINITIONS ============
Expand Down Expand Up @@ -873,6 +896,33 @@ export const PYTHON_TEST_SCHEMAS: ExpectedTableSchema[] = [
{ name: "status_code", type: "Float64" },
],
},
// Materialized column test table
{
tableName: "MaterializedTest",
columns: [
{ name: "id", type: "String" },
{ name: "timestamp", type: /DateTime\('UTC'\)/ },
{ name: "user_id", type: "String" },
{
name: "event_date",
type: /Date(32)?/,
materialized: "toDate(timestamp)",
},
{
name: "user_hash",
type: "UInt64",
materialized: "cityHash64(user_id)",
},
{ name: "log_blob", type: "JSON", codec: "ZSTD(3)" },
{
name: "combination_hash",
type: "Array(UInt64)",
materialized:
"arrayMap(kv -> cityHash64(kv.1, kv.2), JSONExtractKeysAndValuesRaw(toString(log_blob)))",
codec: "ZSTD(1)",
},
],
},
];

// ============ HELPER FUNCTIONS ============
Expand Down
1 change: 1 addition & 0 deletions apps/framework-cli/src/cli/local_webserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3547,6 +3547,7 @@ mod tests {
comment: None,
ttl: None,
codec: None,
materialized: None,
}],
order_by: OrderBy::Fields(vec!["id".to_string()]),
partition_by: None,
Expand Down
5 changes: 5 additions & 0 deletions apps/framework-cli/src/cli/routines/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ mod tests {
comment: None,
ttl: None,
codec: None,
materialized: None,
}],
order_by: OrderBy::Fields(vec!["id".to_string()]),
partition_by: None,
Expand Down Expand Up @@ -800,6 +801,7 @@ mod tests {
comment: None,
ttl: None,
codec: None,
materialized: None,
});
table
}
Expand Down Expand Up @@ -1144,6 +1146,7 @@ mod tests {
comment: None,
ttl: None,
codec: None,
materialized: None,
},
after_column: None,
database: Some("bad_db".to_string()),
Expand All @@ -1162,6 +1165,7 @@ mod tests {
comment: None,
ttl: None,
codec: None,
materialized: None,
},
after_column: Column {
name: "col".to_string(),
Expand All @@ -1174,6 +1178,7 @@ mod tests {
comment: None,
ttl: None,
codec: None,
materialized: None,
},
database: Some("another_bad_db".to_string()),
cluster_name: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ mod tests {
comment: None,
ttl: None,
codec: None,
materialized: None,
}],
order_by: OrderBy::Fields(vec!["id".to_string()]),
partition_by: None,
Expand Down Expand Up @@ -613,6 +614,7 @@ mod tests {
comment: None,
ttl: None,
codec: None,
materialized: None,
});

let mock_client = MockOlapClient {
Expand Down Expand Up @@ -683,6 +685,7 @@ mod tests {
comment: None,
ttl: None,
codec: None,
materialized: None,
};
actual_table.columns.push(timestamp_col.clone());
infra_table.columns.push(timestamp_col);
Expand Down
9 changes: 9 additions & 0 deletions apps/framework-cli/src/framework/core/infrastructure/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,8 @@ pub struct Column {
pub ttl: Option<String>,
#[serde(skip_serializing_if = "Option::is_none", default)]
pub codec: Option<String>, // Compression codec expression (e.g., "ZSTD(3)", "Delta, LZ4")
#[serde(skip_serializing_if = "Option::is_none", default)]
pub materialized: Option<String>, // MATERIALIZED column expression
}

#[derive(Debug, Clone, Eq, PartialEq, Hash)]
Expand Down Expand Up @@ -1192,6 +1194,7 @@ impl Column {
comment: self.comment.clone(),
ttl: self.ttl.clone(),
codec: self.codec.clone(),
materialized: self.materialized.clone(),
special_fields: Default::default(),
}
}
Expand All @@ -1215,6 +1218,7 @@ impl Column {
comment: proto.comment,
ttl: proto.ttl,
codec: proto.codec,
materialized: proto.materialized,
}
}
}
Expand Down Expand Up @@ -1595,6 +1599,7 @@ mod tests {
comment: None,
ttl: None,
codec: None,
materialized: None,
};

let json = serde_json::to_string(&nested_column).unwrap();
Expand All @@ -1616,6 +1621,7 @@ mod tests {
comment: Some("[MOOSE_METADATA:DO_NOT_MODIFY] {\"version\":1,\"enum\":{\"name\":\"TestEnum\",\"members\":[]}}".to_string()),
ttl: None,
codec: None,
materialized: None,
};

// Convert to proto and back
Expand All @@ -1640,6 +1646,7 @@ mod tests {
comment: None,
ttl: None,
codec: None,
materialized: None,
};

let proto = column_without_comment.to_proto();
Expand Down Expand Up @@ -1825,6 +1832,7 @@ mod tests {
comment: None,
ttl: None,
codec: None,
materialized: None,
},
Column {
name: "name".to_string(),
Expand All @@ -1837,6 +1845,7 @@ mod tests {
comment: None,
ttl: None,
codec: None,
materialized: None,
},
];

Expand Down
Loading
Loading