public boolean harmonize ( NodeSchema otherSchema , String schemaKindName ) { if ( size ( ) != otherSchema . size ( ) ) { throw new PlanningErrorException ( "The " + schemaKindName + "schema and the statement output schemas have different lengths." ) ; } boolean changedSomething = false ; for ( int idx = 0 ; idx < size ( ) ; idx += 1 ) { SchemaColumn myColumn = getColumn ( idx ) ; SchemaColumn otherColumn = otherSchema . getColumn ( idx ) ; VoltType myType = myColumn . getValueType ( ) ; VoltType otherType = otherColumn . getValueType ( ) ; VoltType commonType = myType ; if ( ! myType . canExactlyRepresentAnyValueOf ( otherType ) ) { if ( otherType . canExactlyRepresentAnyValueOf ( myType ) ) { commonType = otherType ; } else { throw new PlanningErrorException ( "The " + schemaKindName + " column type and the statement output type for column " + idx + " are incompatible." ) ; } } if ( myType != commonType ) { changedSomething = true ; myColumn . setValueType ( commonType ) ; } // Now determine the length, and the "in bytes" flag if needed assert ( myType . isVariableLength ( ) == otherType . isVariableLength ( ) ) ; // The type will be one of: // - fixed size // - VARCHAR (need special logic for bytes vs. chars) // - Some other variable length type int commonSize ; if ( ! myType . isVariableLength ( ) ) { commonSize = myType . getLengthInBytesForFixedTypesWithoutCheck ( ) ; } else if ( myType == VoltType . STRING ) { boolean myInBytes = myColumn . getInBytes ( ) ; boolean otherInBytes = otherColumn . getInBytes ( ) ; if ( myInBytes == otherInBytes ) { commonSize = Math . max ( myColumn . getValueSize ( ) , otherColumn . getValueSize ( ) ) ; } else { // one is in bytes and the other is in characters int mySizeInBytes = ( myColumn . getInBytes ( ) ? 1 : 4 ) * myColumn . getValueSize ( ) ; int otherSizeInBytes = ( otherColumn . getInBytes ( ) ? 1 : 4 ) * otherColumn . getValueSize ( ) ; if ( ! myColumn . getInBytes ( ) ) { myColumn . setInBytes ( true ) ; changedSomething = true ; } commonSize = Math . max ( mySizeInBytes , otherSizeInBytes ) ; if ( commonSize > VoltType . MAX_VALUE_LENGTH ) { commonSize = VoltType . MAX_VALUE_LENGTH ; } } } else { commonSize = Math . max ( myColumn . getValueSize ( ) , otherColumn . getValueSize ( ) ) ; } if ( commonSize != myColumn . getValueSize ( ) ) { myColumn . setValueSize ( commonSize ) ; changedSomething = true ; } } return changedSomething ; }
Modifies this schema such that its columns can accommodate both values of its own types and that of otherSchema . Does not modify otherSchema .