(
scx: &StatementContext,
explain_schema: ExplainSinkSchemaStatement<Aug>,
)
| 804 | } |
| 805 | |
| 806 | pub fn plan_explain_schema( |
| 807 | scx: &StatementContext, |
| 808 | explain_schema: ExplainSinkSchemaStatement<Aug>, |
| 809 | ) -> Result<Plan, PlanError> { |
| 810 | let ExplainSinkSchemaStatement { |
| 811 | schema_for, |
| 812 | // Parser limits to JSON. |
| 813 | format: _, |
| 814 | mut statement, |
| 815 | } = explain_schema; |
| 816 | |
| 817 | // Force the sink's name to one that's guaranteed not to exist, by virtue of |
| 818 | // being a non-existent item in a schema under the system's control, so that |
| 819 | // `plan_create_sink` doesn't complain about the name already existing. |
| 820 | statement.name = Some(UnresolvedItemName::qualified(&[ |
| 821 | ident!("mz_catalog"), |
| 822 | ident!("mz_explain_schema"), |
| 823 | ])); |
| 824 | |
| 825 | crate::pure::purify_create_sink_avro_doc_on_options( |
| 826 | scx.catalog, |
| 827 | *statement.from.item_id(), |
| 828 | &mut statement.format, |
| 829 | )?; |
| 830 | |
| 831 | match ddl::plan_create_sink(scx, statement)? { |
| 832 | Plan::CreateSink(CreateSinkPlan { sink, .. }) => match sink.connection { |
| 833 | StorageSinkConnection::Kafka(KafkaSinkConnection { |
| 834 | format: |
| 835 | KafkaSinkFormat { |
| 836 | key_format, |
| 837 | value_format: |
| 838 | KafkaSinkFormatType::Avro { |
| 839 | schema: value_schema, |
| 840 | .. |
| 841 | }, |
| 842 | .. |
| 843 | }, |
| 844 | .. |
| 845 | }) => { |
| 846 | let schema = match schema_for { |
| 847 | ExplainSinkSchemaFor::Key => key_format |
| 848 | .and_then(|f| match f { |
| 849 | KafkaSinkFormatType::Avro { schema, .. } => Some(schema), |
| 850 | _ => None, |
| 851 | }) |
| 852 | .ok_or_else(|| sql_err!("CREATE SINK does not have a key"))?, |
| 853 | ExplainSinkSchemaFor::Value => value_schema, |
| 854 | }; |
| 855 | |
| 856 | Ok(Plan::ExplainSinkSchema(ExplainSinkSchemaPlan { |
| 857 | sink_from: sink.from, |
| 858 | json_schema: schema, |
| 859 | })) |
| 860 | } |
| 861 | _ => bail_unsupported!( |
| 862 | "EXPLAIN SCHEMA is only available for Kafka sinks with Avro schemas" |
| 863 | ), |
no test coverage detected