@@ -47,7 +47,7 @@ use crate::{
47
47
TableProviderFilterPushDown , TableSource , WriteOp ,
48
48
} ;
49
49
50
- use arrow:: datatypes:: { DataType , Schema , SchemaRef } ;
50
+ use arrow:: datatypes:: { DataType , Field , Schema , SchemaRef } ;
51
51
use datafusion_common:: display:: ToStringifiedPlan ;
52
52
use datafusion_common:: {
53
53
get_target_functional_dependencies, plan_datafusion_err, plan_err, Column , DFField ,
@@ -890,6 +890,7 @@ impl LogicalPlanBuilder {
890
890
pub fn cross_join ( self , right : LogicalPlan ) -> Result < Self > {
891
891
let join_schema =
892
892
build_join_schema ( self . plan . schema ( ) , right. schema ( ) , & JoinType :: Inner ) ?;
893
+ println ! ( "left is {:?} \n right is {:?}" , self . plan, right) ;
893
894
Ok ( Self :: from ( LogicalPlan :: CrossJoin ( CrossJoin {
894
895
left : Arc :: new ( self . plan ) ,
895
896
right : Arc :: new ( right) ,
@@ -1124,7 +1125,28 @@ impl LogicalPlanBuilder {
1124
1125
) ?) )
1125
1126
}
1126
1127
}
1127
-
1128
+ pub fn change_redundant_column ( fields : Vec < DFField > ) -> Vec < DFField > {
1129
+ let mut name_map = HashMap :: new ( ) ;
1130
+ fields
1131
+ . into_iter ( )
1132
+ . map ( |field| {
1133
+ if !name_map. contains_key ( field. name ( ) ) {
1134
+ name_map. insert ( field. name ( ) . to_string ( ) , 0 ) ;
1135
+ field
1136
+ } else {
1137
+ let cur_cnt = & name_map. get ( field. name ( ) ) ;
1138
+ let name = field. name ( ) . to_string ( ) + ":" + & cur_cnt. unwrap ( ) . to_string ( ) ;
1139
+ name_map. insert ( field. name ( ) . to_string ( ) , cur_cnt. unwrap ( ) + 1 ) ;
1140
+ DFField :: new (
1141
+ field. qualifier ( ) . cloned ( ) ,
1142
+ & name,
1143
+ field. data_type ( ) . clone ( ) ,
1144
+ field. is_nullable ( ) ,
1145
+ )
1146
+ }
1147
+ } )
1148
+ . collect ( )
1149
+ }
1128
1150
/// Creates a schema for a join operation.
1129
1151
/// The fields from the left side are first
1130
1152
pub fn build_join_schema (
@@ -1184,13 +1206,16 @@ pub fn build_join_schema(
1184
1206
right_fields. clone ( )
1185
1207
}
1186
1208
} ;
1209
+ //println!("total fields is {:?}", fields);
1187
1210
let func_dependencies = left. functional_dependencies ( ) . join (
1188
1211
right. functional_dependencies ( ) ,
1189
1212
join_type,
1190
1213
left_fields. len ( ) ,
1191
1214
) ;
1215
+ // println!("func_dependencies is {:?}", func_dependencies);
1192
1216
let mut metadata = left. metadata ( ) . clone ( ) ;
1193
1217
metadata. extend ( right. metadata ( ) . clone ( ) ) ;
1218
+ // let schema = DFSchema::new_with_metadata(change_redundant_column(fields), metadata)?;
1194
1219
let schema = DFSchema :: new_with_metadata ( fields, metadata) ?;
1195
1220
schema. with_functional_dependencies ( func_dependencies)
1196
1221
}
@@ -1231,12 +1256,16 @@ fn add_group_by_exprs_from_dependencies(
1231
1256
}
1232
1257
Ok ( group_expr)
1233
1258
}
1259
+ pub ( crate ) fn validate_unique_names_with_table < ' a > ( ) {
1260
+ unimplemented ! ( )
1261
+ }
1234
1262
/// Errors if one or more expressions have equal names.
1235
1263
pub ( crate ) fn validate_unique_names < ' a > (
1236
1264
node_name : & str ,
1237
1265
expressions : impl IntoIterator < Item = & ' a Expr > ,
1238
1266
) -> Result < ( ) > {
1239
1267
let mut unique_names = HashMap :: new ( ) ;
1268
+
1240
1269
expressions. into_iter ( ) . enumerate ( ) . try_for_each ( |( position, expr) | {
1241
1270
let name = expr. display_name ( ) ?;
1242
1271
match unique_names. get ( & name) {
@@ -1245,6 +1274,7 @@ pub(crate) fn validate_unique_names<'a>(
1245
1274
Ok ( ( ) )
1246
1275
} ,
1247
1276
Some ( ( existing_position, existing_expr) ) => {
1277
+ //println!("node_name is {}, existing expr is {:?}", node_name, existing_expr);
1248
1278
plan_err ! ( "{node_name} require unique expression names \
1249
1279
but the expression \" {existing_expr}\" at position {existing_position} and \" {expr}\" \
1250
1280
at position {position} have the same name. Consider aliasing (\" AS\" ) one of them."
@@ -1360,6 +1390,7 @@ pub fn project(
1360
1390
let mut projected_expr = vec ! [ ] ;
1361
1391
for e in expr {
1362
1392
let e = e. into ( ) ;
1393
+ //println!("cur_expression is {:?}", e);
1363
1394
match e {
1364
1395
Expr :: Wildcard { qualifier : None } => {
1365
1396
projected_expr. extend ( expand_wildcard ( input_schema, & plan, None ) ?)
@@ -1375,6 +1406,10 @@ pub fn project(
1375
1406
. push ( columnize_expr ( normalize_col ( e, & plan) ?, input_schema) ) ,
1376
1407
}
1377
1408
}
1409
+ // println!(
1410
+ // "before validation the projection name is {:?} \n and the expression is {:?}",
1411
+ // plan, projected_expr
1412
+ // );
1378
1413
validate_unique_names ( "Projections" , projected_expr. iter ( ) ) ?;
1379
1414
1380
1415
Projection :: try_new ( projected_expr, Arc :: new ( plan) ) . map ( LogicalPlan :: Projection )
0 commit comments