public void initBatch ( TypeDescription orcSchema , StructField [ ] requiredFields , int [ ] requestedDataColIds , int [ ] requestedPartitionColIds , InternalRow partitionValues ) { wrap = new VectorizedRowBatchWrap ( orcSchema . createRowBatch ( capacity ) ) ; assert ( ! wrap . batch ( ) . selectedInUse ) ; // `selectedInUse` should be initialized with `false`. assert ( requiredFields . length == requestedDataColIds . length ) ; assert ( requiredFields . length == requestedPartitionColIds . length ) ; // If a required column is also partition column, use partition value and don't read from file. for ( int i = 0 ; i < requiredFields . length ; i ++ ) { if ( requestedPartitionColIds [ i ] != - 1 ) { requestedDataColIds [ i ] = - 1 ; } } this . requiredFields = requiredFields ; this . requestedDataColIds = requestedDataColIds ; StructType resultSchema = new StructType ( requiredFields ) ; // Just wrap the ORC column vector instead of copying it to Spark column vector. orcVectorWrappers = new org . apache . spark . sql . vectorized . ColumnVector [ resultSchema . length ( ) ] ; for ( int i = 0 ; i < requiredFields . length ; i ++ ) { DataType dt = requiredFields [ i ] . dataType ( ) ; if ( requestedPartitionColIds [ i ] != - 1 ) { OnHeapColumnVector partitionCol = new OnHeapColumnVector ( capacity , dt ) ; ColumnVectorUtils . populate ( partitionCol , partitionValues , requestedPartitionColIds [ i ] ) ; partitionCol . setIsConstant ( ) ; orcVectorWrappers [ i ] = partitionCol ; } else { int colId = requestedDataColIds [ i ] ; // Initialize the missing columns once. if ( colId == - 1 ) { OnHeapColumnVector missingCol = new OnHeapColumnVector ( capacity , dt ) ; missingCol . putNulls ( 0 , capacity ) ; missingCol . setIsConstant ( ) ; orcVectorWrappers [ i ] = missingCol ; } else { orcVectorWrappers [ i ] = new OrcColumnVector ( dt , wrap . batch ( ) . cols [ colId ] ) ; } } } columnarBatch = new ColumnarBatch ( orcVectorWrappers ) ; }
Initialize columnar batch by setting required schema and partition information . With this information this creates ColumnarBatch with the full schema .