@@ -4,7 +4,6 @@ use crate::expression::ScalarExpression;
44use crate :: types:: tuple:: EMPTY_TUPLE ;
55use crate :: types:: value:: ValueRef ;
66use crate :: types:: { ColumnId , LogicalType } ;
7- use serde:: { Deserialize , Serialize } ;
87use serde_macros:: ReferenceSerialization ;
98use sqlparser:: ast:: CharLengthUnits ;
109use std:: hash:: Hash ;
@@ -30,12 +29,13 @@ impl From<ColumnCatalog> for ColumnRef {
3029
3130#[ derive( Debug , Clone , Hash , Eq , PartialEq , ReferenceSerialization ) ]
3231pub struct ColumnCatalog {
33- pub summary : ColumnSummary ,
34- pub nullable : bool ,
35- pub desc : ColumnDesc ,
32+ summary : ColumnSummary ,
33+ nullable : bool ,
34+ desc : ColumnDesc ,
35+ in_join : bool ,
3636}
3737
38- #[ derive( Debug , Clone , Serialize , Deserialize , Hash , Eq , PartialEq ) ]
38+ #[ derive( Debug , Clone , Hash , Eq , PartialEq ) ]
3939pub enum ColumnRelation {
4040 None ,
4141 Table {
@@ -44,12 +44,24 @@ pub enum ColumnRelation {
4444 } ,
4545}
4646
47- #[ derive( Debug , Clone , Hash , Eq , PartialEq , Serialize , Deserialize , ReferenceSerialization ) ]
47+ #[ derive( Debug , Clone , Hash , Eq , PartialEq , ReferenceSerialization ) ]
4848pub struct ColumnSummary {
4949 pub name : String ,
5050 pub relation : ColumnRelation ,
5151}
5252
53+ impl ColumnRef {
54+ pub ( crate ) fn nullable_for_join ( & self , nullable : bool ) -> Option < ColumnRef > {
55+ if self . nullable == nullable {
56+ return None ;
57+ }
58+ let mut temp = ColumnCatalog :: clone ( self ) ;
59+ temp. nullable = nullable;
60+ temp. in_join = true ;
61+ Some ( ColumnRef :: from ( temp) )
62+ }
63+ }
64+
5365impl ColumnCatalog {
5466 pub fn new ( column_name : String , nullable : bool , column_desc : ColumnDesc ) -> ColumnCatalog {
5567 ColumnCatalog {
@@ -59,6 +71,21 @@ impl ColumnCatalog {
5971 } ,
6072 nullable,
6173 desc : column_desc,
74+ in_join : false ,
75+ }
76+ }
77+
78+ pub ( crate ) fn direct_new (
79+ summary : ColumnSummary ,
80+ nullable : bool ,
81+ column_desc : ColumnDesc ,
82+ in_join : bool ,
83+ ) -> ColumnCatalog {
84+ ColumnCatalog {
85+ summary,
86+ nullable,
87+ desc : column_desc,
88+ in_join,
6289 }
6390 }
6491
@@ -77,13 +104,18 @@ impl ColumnCatalog {
77104 None ,
78105 )
79106 . unwrap ( ) ,
107+ in_join : false ,
80108 }
81109 }
82110
83111 pub ( crate ) fn summary ( & self ) -> & ColumnSummary {
84112 & self . summary
85113 }
86114
115+ pub ( crate ) fn summary_mut ( & mut self ) -> & mut ColumnSummary {
116+ & mut self . summary
117+ }
118+
87119 pub fn id ( & self ) -> Option < ColumnId > {
88120 match & self . summary . relation {
89121 ColumnRelation :: None => None ,
@@ -120,6 +152,14 @@ impl ColumnCatalog {
120152 } ;
121153 }
122154
155+ pub fn in_join ( & self ) -> bool {
156+ self . in_join
157+ }
158+
159+ pub fn nullable ( & self ) -> bool {
160+ self . nullable
161+ }
162+
123163 pub fn datatype ( & self ) -> & LogicalType {
124164 & self . desc . column_datatype
125165 }
@@ -132,10 +172,13 @@ impl ColumnCatalog {
132172 . transpose ( )
133173 }
134174
135- #[ allow( dead_code) ]
136175 pub ( crate ) fn desc ( & self ) -> & ColumnDesc {
137176 & self . desc
138177 }
178+
179+ pub ( crate ) fn desc_mut ( & mut self ) -> & mut ColumnDesc {
180+ & mut self . desc
181+ }
139182}
140183
141184/// The descriptor of a column.
0 commit comments