@@ -27,7 +27,6 @@ use std::ops::Index;
2727use std:: str:: FromStr ;
2828
2929pub use _serde:: RawLiteral ;
30- use bitvec:: vec:: BitVec ;
3130use chrono:: { DateTime , NaiveDate , NaiveDateTime , NaiveTime , TimeZone , Utc } ;
3231use num_bigint:: BigInt ;
3332use ordered_float:: OrderedFloat ;
@@ -1726,102 +1725,53 @@ impl Literal {
17261725#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
17271726pub struct Struct {
17281727 /// Vector to store the field values
1729- fields : Vec < Literal > ,
1730- /// Null bitmap
1731- null_bitmap : BitVec ,
1728+ fields : Vec < Option < Literal > > ,
17321729}
17331730
17341731impl Struct {
17351732 /// Create a empty struct.
17361733 pub fn empty ( ) -> Self {
1737- Self {
1738- fields : Vec :: new ( ) ,
1739- null_bitmap : BitVec :: new ( ) ,
1740- }
1734+ Self { fields : Vec :: new ( ) }
17411735 }
17421736
17431737 /// Create a iterator to read the field in order of field_value.
17441738 pub fn iter ( & self ) -> impl ExactSizeIterator < Item = Option < & Literal > > {
1745- self . null_bitmap . iter ( ) . zip ( self . fields . iter ( ) ) . map (
1746- |( null, value) | {
1747- if * null {
1748- None
1749- } else {
1750- Some ( value)
1751- }
1752- } ,
1753- )
1739+ self . fields . iter ( ) . map ( |field| field. as_ref ( ) )
17541740 }
17551741
17561742 /// returns true if the field at position `index` is null
17571743 pub fn is_null_at_index ( & self , index : usize ) -> bool {
1758- self . null_bitmap [ index]
1744+ self . fields [ index] . is_none ( )
17591745 }
17601746
17611747 /// Return fields in the struct.
1762- pub fn fields ( & self ) -> & [ Literal ] {
1748+ pub fn fields ( & self ) -> & [ Option < Literal > ] {
17631749 & self . fields
17641750 }
17651751}
17661752
17671753impl Index < usize > for Struct {
1768- type Output = Literal ;
1754+ type Output = Option < Literal > ;
17691755
17701756 fn index ( & self , idx : usize ) -> & Self :: Output {
17711757 & self . fields [ idx]
17721758 }
17731759}
17741760
1775- /// An iterator that moves out of a struct.
1776- pub struct StructValueIntoIter {
1777- null_bitmap : bitvec:: boxed:: IntoIter ,
1778- fields : std:: vec:: IntoIter < Literal > ,
1779- }
1780-
1781- impl Iterator for StructValueIntoIter {
1782- type Item = Option < Literal > ;
1783-
1784- fn next ( & mut self ) -> Option < Self :: Item > {
1785- match ( self . null_bitmap . next ( ) , self . fields . next ( ) ) {
1786- ( Some ( null) , Some ( value) ) => Some ( if null { None } else { Some ( value) } ) ,
1787- _ => None ,
1788- }
1789- }
1790- }
1791-
17921761impl IntoIterator for Struct {
17931762 type Item = Option < Literal > ;
17941763
1795- type IntoIter = StructValueIntoIter ;
1764+ type IntoIter = std :: vec :: IntoIter < Option < Literal > > ;
17961765
17971766 fn into_iter ( self ) -> Self :: IntoIter {
1798- StructValueIntoIter {
1799- null_bitmap : self . null_bitmap . into_iter ( ) ,
1800- fields : self . fields . into_iter ( ) ,
1801- }
1767+ self . fields . into_iter ( )
18021768 }
18031769}
18041770
18051771impl FromIterator < Option < Literal > > for Struct {
18061772 fn from_iter < I : IntoIterator < Item = Option < Literal > > > ( iter : I ) -> Self {
1807- let mut fields = Vec :: new ( ) ;
1808- let mut null_bitmap = BitVec :: new ( ) ;
1809-
1810- for value in iter. into_iter ( ) {
1811- match value {
1812- Some ( value) => {
1813- fields. push ( value) ;
1814- null_bitmap. push ( false )
1815- }
1816- None => {
1817- fields. push ( Literal :: Primitive ( PrimitiveLiteral :: Boolean ( false ) ) ) ;
1818- null_bitmap. push ( true )
1819- }
1820- }
1821- }
18221773 Struct {
1823- fields,
1824- null_bitmap,
1774+ fields : iter. into_iter ( ) . collect ( ) ,
18251775 }
18261776 }
18271777}
@@ -3402,7 +3352,7 @@ mod tests {
34023352 match ( & desered_literal, & struct_literal) {
34033353 ( Literal :: Struct ( desered) , Literal :: Struct ( expected) ) => {
34043354 match ( & desered. fields [ 0 ] , & expected. fields [ 0 ] ) {
3405- ( Literal :: Map ( desered) , Literal :: Map ( expected) ) => {
3355+ ( Some ( Literal :: Map ( desered) ) , Some ( Literal :: Map ( expected) ) ) => {
34063356 assert ! ( desered. has_same_content( expected) )
34073357 }
34083358 _ => {
0 commit comments