@@ -1521,6 +1521,9 @@ private static Vector validateVectorType(final String colName, final DATA_TYPE c
15211521 if (colType != null ) {
15221522 resolvedType = colType ;
15231523 }
1524+ if (extraParam != -1 && isDecimalType (resolvedType )) {
1525+ validateDecimalScale (resolvedType , extraParam );
1526+ }
15241527 if (extraParam >= 0 && isDecimalType (resolvedType ) && vector instanceof AbstractVector ) {
15251528 int vectorExtraParam = ((AbstractVector ) vector ).getExtraParamForType ();
15261529 if (vectorExtraParam != extraParam ) {
@@ -1820,6 +1823,10 @@ private static Vector tryCreateFastVectorFromList(final DATA_TYPE colType, final
18201823 }
18211824
18221825 private static int resolveExtraParam (final DATA_TYPE colType , final int declaredExtraParam , final Object sampleValue ) {
1826+ if (isDecimalType (colType ) && declaredExtraParam != -1 ) {
1827+ validateDecimalScale (colType , declaredExtraParam );
1828+ return declaredExtraParam ;
1829+ }
18231830 if (declaredExtraParam >= 0 ) {
18241831 return declaredExtraParam ;
18251832 }
@@ -1832,6 +1839,29 @@ private static int resolveExtraParam(final DATA_TYPE colType, final int declared
18321839 return -1 ;
18331840 }
18341841
1842+ private static void validateDecimalScale (final DATA_TYPE colType , final int scale ) {
1843+ int upperBound = getDecimalScaleUpperBound (colType );
1844+ if (scale < 0 || scale > upperBound ) {
1845+ throw new RuntimeException ("Scale " + scale + " is out of bounds, it must be in [0," + upperBound + "]." );
1846+ }
1847+ }
1848+
1849+ private static int getDecimalScaleUpperBound (final DATA_TYPE colType ) {
1850+ switch (colType ) {
1851+ case DT_DECIMAL32 :
1852+ case DT_DECIMAL32_ARRAY :
1853+ return 9 ;
1854+ case DT_DECIMAL64 :
1855+ case DT_DECIMAL64_ARRAY :
1856+ return 18 ;
1857+ case DT_DECIMAL128 :
1858+ case DT_DECIMAL128_ARRAY :
1859+ return 38 ;
1860+ default :
1861+ throw new IllegalArgumentException ("Column type " + colType .getName () + " is not a decimal type." );
1862+ }
1863+ }
1864+
18351865 private static Object getSampleValue (final Object col ) {
18361866 if (col instanceof Collection <?>) {
18371867 return findFirstNonNullValue ((Collection <?>) col );
0 commit comments