Class ValidateUtf8


public class ValidateUtf8 extends TextArgumentFunction
VALIDATE_UTF8(x) — the input as a string when its bytes are valid UTF-8.

It reads its argument as TEXT, so a BINARY is an argument-type error rather than the obvious input: live refuses VALIDATE_UTF8(bn) at compile time and answers over a VARCHAR, a NUMBER and a VARIANT alike.

Indistinguishable from TryValidateUtf8 on every reachable input, which is measured rather than assumed. The pair would normally differ over INVALID UTF-8 — the TRY_ spelling answering NULL where the plain one raises — but no argument this function accepts can carry any: a BINARY is refused before evaluation, a lone surrogate is refused by the string-literal reader itself ("high surrogate '\\uD800' must be followed by a low surrogate"), and a binary CAST to VARCHAR has already been decoded by the time it arrives. So the divergent branch is unreachable, and inventing a refusal for it would be inventing behaviour nothing can observe.

  • Constructor Details

    • ValidateUtf8

      public ValidateUtf8()
  • Method Details

    • binaryRejection

      public SemiStructuredRejection binaryRejection(int position)
      Description copied from class: BuiltInFunction
      The refusal a position gives a statically BINARY-typed value.

      A fifth question rather than a reuse of any of the four above, because BINARY sits on the opposite side of them: it is a scalar a text function is happy to be handed almost everywhere — live answers LENGTH(bn), SUBSTR(bn, 1, 1), CONCAT(bn, bn) — where an OBJECT is refused. Only the functions that read their argument AS TEXT and would have to decode it refuse one, and they say so themselves: VALIDATE_UTF8(bn) and TRY_VALIDATE_UTF8(bn) are "Invalid argument types for function 'TRY_VALIDATE_UTF8': (BINARY(5))" while the same call over a VARCHAR, and even over a NUMBER, returns a value.

      The default is NONE: undeclared means unconstrained, as for the other four.

      Overrides:
      binaryRejection in class BuiltInFunction
      Parameters:
      position - the zero-based argument position being asked about
      Returns:
      the refusal this position gives a BINARY value; by default none
    • evaluate

      public Object evaluate(List<Object> args)
      Description copied from class: BuiltInFunction
      Computes the function's result over its already-evaluated argument values. A SQL NULL argument arrives as Java null, and returning null makes the SQL result NULL.
      Specified by:
      evaluate in class BuiltInFunction
      Parameters:
      args - the argument values, in call order
      Returns:
      the function's value for these arguments, or null for SQL NULL
    • getMinArgCount

      public int getMinArgCount()
      Description copied from class: BuiltInFunction
      The fewest arguments a call to this function may pass; fewer is an argument-count error.
      Specified by:
      getMinArgCount in class BuiltInFunction
      Returns:
      the minimum accepted argument count
    • getMaxArgCount

      public int getMaxArgCount()
      Description copied from class: BuiltInFunction
      The most arguments a call to this function may pass; Integer.MAX_VALUE marks a variadic function (see BuiltInFunction.isVariadic()).
      Specified by:
      getMaxArgCount in class BuiltInFunction
      Returns:
      the maximum accepted argument count