Github user nareshpr commented on a diff in the pull request: https://github.com/apache/incubator-carbondata/pull/641#discussion_r106112796 --- Diff: integration/spark-common/src/main/scala/org/apache/carbondata/spark/util/CarbonScalaUtil.scala --- @@ -194,4 +196,102 @@ object CarbonScalaUtil { } } } + + /** + * This method will validate a column for its data type and check whether the column data type + * can be modified and update if conditions are met + * + * @param dataTypeInfo + * @param carbonColumn + */ + def validateColumnDataType(dataTypeInfo: DataTypeInfo, carbonColumn: CarbonColumn): Unit = { + carbonColumn.getDataType.getName match { + case "INT" => + if (!dataTypeInfo.dataType.equals("bigint")) { + sys + .error(s"Given column ${ carbonColumn.getColName } with data type ${ + carbonColumn + .getDataType.getName + } cannot be modified. Int can only be changed to bigInt") + } + case "DECIMAL" => + if (!dataTypeInfo.dataType.equals("decimal")) { + sys + .error(s"Given column ${ carbonColumn.getColName } with data type ${ + carbonColumn.getDataType.getName + } cannot be modified. Decimal can be only be changed to Decimal of higher precision") + } + if (dataTypeInfo.precision <= carbonColumn.getColumnSchema.getPrecision) { + sys + .error(s"Given column ${ + carbonColumn + .getColName + } cannot be modified. Specified precision value ${ + dataTypeInfo + .precision + } should be greater or equal to current precision value ${ + carbonColumn.getColumnSchema + .getPrecision + }") + } else if (dataTypeInfo.scale <= carbonColumn.getColumnSchema.getScale) { + sys + .error(s"Given column ${ + carbonColumn + .getColName + } cannot be modified. Specified scale value ${ + dataTypeInfo + .scale + } should be greater or equal to current scale value ${ + carbonColumn.getColumnSchema + .getScale + }") + } else { + // difference of precision and scale specified by user should not be less than the + // difference of already existing precision and scale else it will result in data loss + val carbonColumnPrecisionScaleDiff = carbonColumn.getColumnSchema.getPrecision - + carbonColumn.getColumnSchema.getScale + val dataInfoPrecisionScaleDiff = dataTypeInfo.precision - dataTypeInfo.scale + if (dataInfoPrecisionScaleDiff < carbonColumnPrecisionScaleDiff) { + sys + .error(s"Given column ${ + carbonColumn + .getColName + } cannot be modified. Specified precision and scale values will lead to data loss") + } + } + case _ => + sys + .error(s"Given column ${ carbonColumn.getColName } with data type ${ + carbonColumn + .getDataType.getName + } cannot be modified. Only Int and Decimal data types are allowed for modification") + } + } + + /** + * This method will create a copy of the same object + * + * @param thriftColumnSchema object to be cloned + * @return + */ + def createColumnSchemaCopyObject(thriftColumnSchema: org.apache.carbondata.format.ColumnSchema) --- End diff -- Done
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---