{"record":{"id":"1ea060c53711634f","repo":"apache/druid","slug":"error-reading-column-s-as-type-s","errorCode":null,"errorMessage":"Error reading column[%s] as type[%s]","messagePattern":"Error reading column\\[(.+?)\\] as type\\[(.+?)\\]","errorType":"validation","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/segment/RowBasedColumnSelectorFactory.java","lineNumber":538,"sourceCode":"        @Nullable\n        @Override\n        public Object getObject()\n        {\n          updateCurrentValue();\n\n          if (expressionType != null && !expressionType.is(ExprType.COMPLEX)) {\n            try {\n              final Object val = ExprEval.bestEffortOf(currentValue).castTo(expressionType).value();\n              if (val != null && expressionType.is(ExprType.DOUBLE) && numberType == ValueType.FLOAT) {\n                // Adjustment for FLOAT. Expressions don't speak float, so we need to cast it ourselves.\n                return ((Number) val).floatValue();\n              } else {\n                return val;\n              }\n            }\n            catch (Exception e) {\n              if (throwParseExceptions) {\n                throw new ParseException(\n                    String.valueOf(currentValue),\n                    \"Error reading column[%s] as type[%s]\",\n                    columnName,\n                    expressionType\n                );\n              } else {\n                // if !throwParseExceptions, return the original uncasted value and hope for the best.\n                return currentValue;\n              }\n            }\n          } else {\n            return currentValue;\n          }\n        }\n\n        @Override\n        public Class<Object> classOfObject()\n        {","sourceCodeStart":520,"sourceCodeEnd":556,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/segment/RowBasedColumnSelectorFactory.java#L520-L556","documentation":"The expression-based object accessor in RowBasedColumnSelectorFactory converts row values to a target expression type. If conversion throws and throwParseExceptions is enabled, it wraps the failure in a ParseException including the offending value, column name, and target type.","triggerScenarios":"Calling getObject(columnName) where the row value cannot be coerced to the declared expression type (e.g. string 'abc' read as LONG/DOUBLE) and throwParseExceptions is true.","commonSituations":"Ingesting dirty data (non-numeric strings into numeric columns); schema drift between rows; SQL queries casting columns to mismatched types over row-based data.","solutions":["Fix or clean the source data so values match the declared column type","Use Cast-to-nullable/TRY_CAST-style handling or disable strict parse behavior where supported (throwParseExceptions=false)","Add input-format parsers/filters during ingestion to reject or transform malformed values","Validate the column's declared expressionType matches the actual row data types"],"exampleFix":"// before: strict accessor throwing on bad data\nrowBasedFactory.makeColumnValueSelector(columnName)\n// after: tolerant conversion with default\nObject v = row.getRaw(columnName);\nLong parsed = v instanceof Number ? ((Number) v).longValue()\n    : NumberUtils.tryParseLong(String.valueOf(v), null);","handlingStrategy":"try-catch","validationCode":"Object v = row.getRaw(col);\nboolean parseable = v instanceof Number || NumberUtils.isParsable(String.valueOf(v));","typeGuard":null,"tryCatchPattern":"try {\n  Object o = selector.getObject();\n} catch (ParseException e) {\n  log.warn(e, \"Row value [%s] not parseable as column [%s]\", e.getErrorMessage(), columnName);\n}","preventionTips":["Clean/validate input data before ingestion","Match declared column types to actual row value types","Use tolerant parse settings for dirty data sources"],"tags":["parse-error","type-conversion","row-based"],"backgroundTag":"schema-validation-failed","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}