Plans an expression in the CHECK position of a `CREATE SOURCE ... FROM WEBHOOK`.
(
scx: &StatementContext,
validate_using: CreateWebhookSourceCheck<Aug>,
)
| 1092 | |
| 1093 | /// Plans an expression in the CHECK position of a `CREATE SOURCE ... FROM WEBHOOK`. |
| 1094 | pub fn plan_webhook_validate_using( |
| 1095 | scx: &StatementContext, |
| 1096 | validate_using: CreateWebhookSourceCheck<Aug>, |
| 1097 | ) -> Result<WebhookValidation, PlanError> { |
| 1098 | let qcx = QueryContext::root(scx, QueryLifetime::Source); |
| 1099 | |
| 1100 | let CreateWebhookSourceCheck { |
| 1101 | options, |
| 1102 | using: mut expr, |
| 1103 | } = validate_using; |
| 1104 | |
| 1105 | let mut column_typs = vec![]; |
| 1106 | let mut column_names = vec![]; |
| 1107 | |
| 1108 | let (bodies, headers, secrets) = options |
| 1109 | .map(|o| (o.bodies, o.headers, o.secrets)) |
| 1110 | .unwrap_or_default(); |
| 1111 | |
| 1112 | // Append all of the bodies so they can be used in the expression. |
| 1113 | let mut body_tuples = vec![]; |
| 1114 | for CreateWebhookSourceBody { alias, use_bytes } in bodies { |
| 1115 | let scalar_type = use_bytes |
| 1116 | .then_some(SqlScalarType::Bytes) |
| 1117 | .unwrap_or(SqlScalarType::String); |
| 1118 | let name = alias |
| 1119 | .map(|a| a.into_string()) |
| 1120 | .unwrap_or_else(|| "body".to_string()); |
| 1121 | |
| 1122 | column_typs.push(SqlColumnType { |
| 1123 | scalar_type, |
| 1124 | nullable: false, |
| 1125 | }); |
| 1126 | column_names.push(name); |
| 1127 | |
| 1128 | // Store the column index so we can be sure to provide this body correctly. |
| 1129 | let column_idx = column_typs.len() - 1; |
| 1130 | // Double check we're consistent with column names. |
| 1131 | assert_eq!( |
| 1132 | column_idx, |
| 1133 | column_names.len() - 1, |
| 1134 | "body column names and types don't match" |
| 1135 | ); |
| 1136 | body_tuples.push((column_idx, use_bytes)); |
| 1137 | } |
| 1138 | |
| 1139 | // Append all of the headers so they can be used in the expression. |
| 1140 | let mut header_tuples = vec![]; |
| 1141 | |
| 1142 | for CreateWebhookSourceHeader { alias, use_bytes } in headers { |
| 1143 | let value_type = use_bytes |
| 1144 | .then_some(SqlScalarType::Bytes) |
| 1145 | .unwrap_or(SqlScalarType::String); |
| 1146 | let name = alias |
| 1147 | .map(|a| a.into_string()) |
| 1148 | .unwrap_or_else(|| "headers".to_string()); |
| 1149 | |
| 1150 | column_typs.push(SqlColumnType { |
| 1151 | scalar_type: SqlScalarType::Map { |
no test coverage detected