{"record":{"id":"de1a565a87033ffb","repo":"apache/iceberg","slug":"unable-to-parse-the-predicate-expression-s","errorCode":null,"errorMessage":"Unable to parse the predicate expression: %s","messagePattern":"Unable to parse the predicate expression: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/SparkTableUtil.java","lineNumber":244,"sourceCode":"   * @param table a table name and (optional) database\n   * @param predicate a predicate on partition columns\n   * @return matching table's partitions\n   */\n  public static List<SparkPartition> getPartitionsByFilter(\n      SparkSession spark, String table, String predicate) {\n    TableIdentifier tableIdent;\n    try {\n      tableIdent = spark.sessionState().sqlParser().parseTableIdentifier(table);\n    } catch (ParseException e) {\n      throw SparkExceptionUtil.toUncheckedException(\n          e, \"Unable to parse the table identifier: %s\", table);\n    }\n\n    Expression unresolvedPredicateExpr;\n    try {\n      unresolvedPredicateExpr = spark.sessionState().sqlParser().parseExpression(predicate);\n    } catch (ParseException e) {\n      throw SparkExceptionUtil.toUncheckedException(\n          e, \"Unable to parse the predicate expression: %s\", predicate);\n    }\n\n    Expression resolvedPredicateExpr = resolveAttrs(spark, table, unresolvedPredicateExpr);\n    return getPartitionsByFilter(spark, tableIdent, resolvedPredicateExpr);\n  }\n\n  /**\n   * Returns partitions that match the specified 'predicate'.\n   *\n   * @param spark a Spark session\n   * @param tableIdent a table identifier\n   * @param predicateExpr a predicate expression on partition columns\n   * @return matching table's partitions\n   */\n  public static List<SparkPartition> getPartitionsByFilter(\n      SparkSession spark, TableIdentifier tableIdent, Expression predicateExpr) {\n    try {","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/SparkTableUtil.java#L226-L262","documentation":"Thrown when Spark's SQL parser cannot parse the predicate string into an Expression in getPartitionsByFilter(spark, table, predicate). SparkTableUtil wraps the ParseException as an unchecked exception including the raw predicate.","triggerScenarios":"Calling SparkTableUtil.getPartitionsByFilter with a predicate string that is not a valid Spark SQL boolean expression — malformed syntax, unsupported functions, unquoted string literals, or an empty string.","commonSituations":"Building predicates with string concatenation that produces invalid SQL; using engine-specific SQL that Spark's parser rejects; passing column names with special characters unquoted; locale/date formatting issues in literal values.","solutions":["Validate the predicate parses first: spark.sessionState().sqlParser().parseExpression(predicate).toString().","Quote column names with backticks and use single quotes for string literals.","Use Spark-legal syntax (e.g. date '2024-01-01' instead of TO_DATE(...) variants the parser rejects).","Build the expression programmatically via functions.expr or Column APIs instead of raw strings when predicates are dynamic."],"exampleFix":"// before\nSparkTableUtil.getPartitionsByFilter(spark, \"db.events\", \"date = 2024-01-01\");\n// after\nSparkTableUtil.getPartitionsByFilter(spark, \"db.events\", \"date = date '2024-01-01'\");","handlingStrategy":"validation","validationCode":"try {\n  spark.sessionState().sqlParser().parseExpression(predicate);\n} catch (ParseException e) {\n  throw new IllegalArgumentException(\"Invalid predicate: \" + predicate, e);\n}","typeGuard":null,"tryCatchPattern":"try {\n  SparkTableUtil.getPartitionsByFilter(spark, table, predicate);\n} catch (RuntimeException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Unable to parse the predicate\")) {\n    // log offending predicate and skip filtering or fail fast\n  } else {\n    throw e;\n  }\n}","preventionTips":["Build predicates with Spark's expr()/Column API instead of string concatenation","Quote columns with backticks and strings with single quotes","Use Spark-legal date literals (date 'YYYY-MM-DD')"],"tags":["spark","sql-parser","predicate-parsing"],"backgroundTag":"invalid-argument-format","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}