{"record":{"id":"4fa0c411d8739fe3","repo":"apache/beam","slug":"jar-path-is-not-instanceof-sqlcharstringliteral","errorCode":null,"errorMessage":"Jar path is not instanceof SqlCharStringLiteral.","messagePattern":"Jar path is not instanceof SqlCharStringLiteral\\.","errorType":"validation","errorClass":"SqlUtil.newContextException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/parser/SqlCreateFunction.java","lineNumber":106,"sourceCode":"  public List<SqlNode> getOperandList() {\n    return Arrays.asList(functionName, jarPath);\n  }\n\n  @Override\n  public void execute(CalcitePrepare.Context context) {\n    final Pair<CalciteSchema, String> pair = SqlDdlNodes.schema(context, true, functionName);\n    SchemaPlus schema = pair.left.plus();\n    String lastName = pair.right;\n    if (!schema.getFunctions(lastName).isEmpty()) {\n      throw SqlUtil.newContextException(\n          functionName.getParserPosition(),\n          RESOURCE.internal(String.format(\"Function %s is already defined.\", lastName)));\n    }\n    JavaUdfLoader udfLoader = new JavaUdfLoader();\n    // TODO(https://github.com/apache/beam/issues/20834) Support qualified function names.\n    List<String> functionPath = ImmutableList.of(lastName);\n    if (!(jarPath instanceof SqlCharStringLiteral)) {\n      throw SqlUtil.newContextException(\n          jarPath.getParserPosition(),\n          RESOURCE.internal(\"Jar path is not instanceof SqlCharStringLiteral.\"));\n    }\n    String unquotedJarPath = ((SqlCharStringLiteral) jarPath).getNlsString().getValue();\n    if (isAggregate) {\n      // Try loading the aggregate function just to make sure it exists. LazyAggregateCombineFn will\n      // need to fetch it again at runtime.\n      udfLoader.loadAggregateFunction(functionPath, unquotedJarPath);\n      LazyAggregateCombineFn<?, ?, ?> combineFn =\n          new LazyAggregateCombineFn<>(functionPath, unquotedJarPath);\n      schema.add(lastName, combineFn.getUdafImpl());\n    } else {\n      ScalarFn scalarFn = udfLoader.loadScalarFunction(functionPath, unquotedJarPath);\n      Method method = ScalarFnReflector.getApplyMethod(scalarFn);\n      Function function = ScalarFunctionImpl.create(method, unquotedJarPath);\n      schema.add(lastName, function);\n    }\n  }","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/parser/SqlCreateFunction.java#L88-L124","documentation":"CREATE FUNCTION requires the USING JAR path to be a string literal (SqlCharStringLiteral). If the jarPath operand parses as any other SqlNode kind (e.g. an identifier, expression, or non-string literal), execute() raises an internal error instead of silently coercing.","triggerScenarios":"Writing the jar location as a quoted identifier, a column-style reference, or any non-string-literal expression in CREATE FUNCTION ... USING JAR, e.g. backticked or unquoted paths.","commonSituations":"Confusing SQL dialect quoting rules (double quotes make identifiers in some dialects); generating DDL programmatically and emitting the path unquoted; copying syntax from non-Beam engines.","solutions":["Quote the jar path as a single-quoted SQL string literal: USING JAR 'gs://bucket/udf.jar'","Avoid double quotes or backticks around the path (they may parse as identifiers)","When generating SQL, emit the path via string-literal escaping"],"exampleFix":"// before\nCREATE FUNCTION udf AS 'com.x.Udf' USING JAR \"gs://bucket/udf.jar\";\n// after\nCREATE FUNCTION udf AS 'com.x.Udf' USING JAR 'gs://bucket/udf.jar';","handlingStrategy":"validation","validationCode":"// Ensure the JAR path is emitted as a single-quoted string literal in generated SQL\nString ddl = \"CREATE FUNCTION \" + fn + \" AS '\" + cls + \"' USING JAR '\" + jarPath.replace(\"'\", \"''\") + \"'\";","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always single-quote the jar path in CREATE FUNCTION","Don't use double quotes/backticks for string values in Beam SQL","Escape single quotes when generating DDL programmatically"],"tags":["sql","ddl","udf","syntax"],"backgroundTag":"invalid-argument-format","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}