@@ -302,12 +302,71 @@ fn get_name_strategy_or_default(name_strategy: Option<AstString>) -> Result<Opti
302
302
}
303
303
}
304
304
305
+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
306
+ pub enum CreateSourceType {
307
+ SharedCdc ,
308
+ /// e.g., shared Kafka source
309
+ SharedNonCdc ,
310
+ NonShared ,
311
+ /// create table with connector
312
+ Table ,
313
+ }
314
+
315
+ impl CreateSourceType {
316
+ pub fn from_with_properties (
317
+ session : & SessionImpl ,
318
+ with_properties : & impl WithPropertiesExt ,
319
+ ) -> Self {
320
+ if with_properties. is_shareable_cdc_connector ( ) {
321
+ CreateSourceType :: SharedCdc
322
+ } else if with_properties. is_shareable_non_cdc_connector ( )
323
+ && session
324
+ . env ( )
325
+ . streaming_config ( )
326
+ . developer
327
+ . enable_shared_source
328
+ && session. config ( ) . streaming_use_shared_source ( )
329
+ {
330
+ CreateSourceType :: SharedNonCdc
331
+ } else {
332
+ CreateSourceType :: NonShared
333
+ }
334
+ }
335
+
336
+ pub fn is_shared ( & self ) -> bool {
337
+ matches ! (
338
+ self ,
339
+ CreateSourceType :: SharedCdc | CreateSourceType :: SharedNonCdc
340
+ )
341
+ }
342
+ }
343
+
305
344
/// Resolves the schema of the source from external schema file.
306
345
/// See <https://www.risingwave.dev/docs/current/sql-create-source> for more information.
307
346
///
308
347
/// Note: the returned schema strictly corresponds to the schema.
309
348
/// Other special columns like additional columns (`INCLUDE`), and `row_id` column are not included.
310
- pub ( crate ) async fn bind_columns_from_source (
349
+ pub async fn bind_columns_from_source (
350
+ session : & SessionImpl ,
351
+ format_encode : & FormatEncodeOptions ,
352
+ with_properties : Either < & WithOptions , & WithOptionsSecResolved > ,
353
+ create_source_type : CreateSourceType ,
354
+ ) -> Result < ( Option < Vec < ColumnCatalog > > , StreamSourceInfo ) > {
355
+ let ( columns_from_resolve_source, mut source_info) =
356
+ if create_source_type == CreateSourceType :: SharedCdc {
357
+ bind_columns_from_source_for_cdc ( session, format_encode) ?
358
+ } else {
359
+ bind_columns_from_source_for_non_cdc ( session, format_encode, with_properties) . await ?
360
+ } ;
361
+ if create_source_type. is_shared ( ) {
362
+ // Note: this field should be called is_shared. Check field doc for more details.
363
+ source_info. cdc_source_job = true ;
364
+ source_info. is_distributed = create_source_type == CreateSourceType :: SharedNonCdc ;
365
+ }
366
+ Ok ( ( columns_from_resolve_source, source_info) )
367
+ }
368
+
369
+ async fn bind_columns_from_source_for_non_cdc (
311
370
session : & SessionImpl ,
312
371
format_encode : & FormatEncodeOptions ,
313
372
with_properties : Either < & WithOptions , & WithOptionsSecResolved > ,
@@ -1542,9 +1601,7 @@ pub async fn bind_create_source_or_table_with_connector(
1542
1601
source_info : StreamSourceInfo ,
1543
1602
include_column_options : IncludeOption ,
1544
1603
col_id_gen : & mut ColumnIdGenerator ,
1545
- // `true` for "create source", `false` for "create table with connector"
1546
- is_create_source : bool ,
1547
- is_shared_non_cdc : bool ,
1604
+ create_source_type : CreateSourceType ,
1548
1605
source_rate_limit : Option < u32 > ,
1549
1606
) -> Result < ( SourceCatalog , DatabaseId , SchemaId ) > {
1550
1607
let session = & handler_args. session ;
@@ -1553,6 +1610,7 @@ pub async fn bind_create_source_or_table_with_connector(
1553
1610
let ( database_id, schema_id) =
1554
1611
session. get_database_and_schema_id_for_create ( schema_name. clone ( ) ) ?;
1555
1612
1613
+ let is_create_source = create_source_type != CreateSourceType :: Table ;
1556
1614
if !is_create_source && with_properties. is_iceberg_connector ( ) {
1557
1615
return Err ( ErrorCode :: BindError (
1558
1616
"can't CREATE TABLE with iceberg connector\n \n Hint: use CREATE SOURCE instead"
@@ -1609,7 +1667,7 @@ pub async fn bind_create_source_or_table_with_connector(
1609
1667
1610
1668
// For shared sources, we will include partition and offset cols in the SourceExecutor's *output*, to be used by the SourceBackfillExecutor.
1611
1669
// For shared CDC source, the schema is different. See debezium_cdc_source_schema, CDC_BACKFILL_TABLE_ADDITIONAL_COLUMNS
1612
- if is_shared_non_cdc {
1670
+ if create_source_type == CreateSourceType :: SharedNonCdc {
1613
1671
let ( columns_exist, additional_columns) = source_add_partition_offset_cols (
1614
1672
& columns,
1615
1673
& with_properties. get_connector ( ) . unwrap ( ) ,
@@ -1748,26 +1806,14 @@ pub async fn handle_create_source(
1748
1806
let format_encode = stmt. format_encode . into_v2_with_warning ( ) ;
1749
1807
let with_properties = bind_connector_props ( & handler_args, & format_encode, true ) ?;
1750
1808
1751
- let create_cdc_source_job = with_properties. is_shareable_cdc_connector ( ) ;
1752
- let is_shared_non_cdc = with_properties. is_shareable_non_cdc_connector ( )
1753
- && session
1754
- . env ( )
1755
- . streaming_config ( )
1756
- . developer
1757
- . enable_shared_source
1758
- && session. config ( ) . streaming_use_shared_source ( ) ;
1759
- let is_shared = create_cdc_source_job || is_shared_non_cdc;
1760
-
1761
- let ( columns_from_resolve_source, mut source_info) = if create_cdc_source_job {
1762
- bind_columns_from_source_for_cdc ( & session, & format_encode) ?
1763
- } else {
1764
- bind_columns_from_source ( & session, & format_encode, Either :: Left ( & with_properties) ) . await ?
1765
- } ;
1766
- if is_shared {
1767
- // Note: this field should be called is_shared. Check field doc for more details.
1768
- source_info. cdc_source_job = true ;
1769
- source_info. is_distributed = !create_cdc_source_job;
1770
- }
1809
+ let create_source_type = CreateSourceType :: from_with_properties ( & session, & * with_properties) ;
1810
+ let ( columns_from_resolve_source, source_info) = bind_columns_from_source (
1811
+ & session,
1812
+ & format_encode,
1813
+ Either :: Left ( & with_properties) ,
1814
+ create_source_type,
1815
+ )
1816
+ . await ?;
1771
1817
let mut col_id_gen = ColumnIdGenerator :: new_initial ( ) ;
1772
1818
1773
1819
let ( source_catalog, database_id, schema_id) = bind_create_source_or_table_with_connector (
@@ -1783,8 +1829,7 @@ pub async fn handle_create_source(
1783
1829
source_info,
1784
1830
stmt. include_column_options ,
1785
1831
& mut col_id_gen,
1786
- true ,
1787
- is_shared_non_cdc,
1832
+ create_source_type,
1788
1833
overwrite_options. source_rate_limit ,
1789
1834
)
1790
1835
. await ?;
@@ -1802,7 +1847,7 @@ pub async fn handle_create_source(
1802
1847
1803
1848
let catalog_writer = session. catalog_writer ( ) ?;
1804
1849
1805
- if is_shared {
1850
+ if create_source_type . is_shared ( ) {
1806
1851
let graph = generate_stream_graph_for_source ( handler_args, source_catalog) ?;
1807
1852
catalog_writer. create_source ( source, Some ( graph) ) . await ?;
1808
1853
} else {
0 commit comments