Class VariantJsonText

java.lang.Object
dev.frostlake.values.VariantJsonText

public final class VariantJsonText extends Object
The JSON TEXT of a semi-structured value in the account's own spelling, which differs from the engine's canonical text in exactly one place — the DOUBLE family. The account displays a DOUBLE exactly as it converts one:
   SELECT ARRAY_CONSTRUCT(1.0::FLOAT)             [1.000000000000000e+00]     the display
   SELECT TO_JSON(ARRAY_CONSTRUCT(1.0::FLOAT))    [1.000000000000000e+00]     the conversion
 

★ THE FAMILY DECIDES, NOT THE VALUE. A DECIMAL and an INTEGER convert exactly as they display — [1.5] stays [1.5] and [1] stays [1] — so this is one family's own rule rather than a number format. The family is read off the parsed node (isFloatingPointNumber), because the canonical TEXT has already been normalised and no longer says which notation it was written in.

★ THE FORM IS %.15e, measured part by part: one digit, a point, FIFTEEN decimals, a lower-case e, an explicit sign, and an exponent of at least two digits that widens rather than truncating — 1e100 is 1.000000000000000e+100 and 1e308 keeps all three. A negative zero keeps its sign (-0.000000000000000e+00).

★ THE SURFACES THAT USE IT are the conversions — TO_JSON, ::VARCHAR and TO_VARCHAR — and the display: the cell a client reads through the driver or the HTTP wire, a whole value or a member alike, and the engine's own display of a container. The one exception is a bare DOUBLE under the STRING conversions, which takes a FLOAT's text instead (see stringConversionTextOf(java.lang.Object)). HASH's canonical value keeps the canonical text, and CONCAT and LISTAGG refuse a container outright.

  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    The JSON text a client reads for a semi-structured value: displayTextOf(dev.frostlake.values.VariantValue), or the canonical text when there is no DOUBLE in it.
    static String
    The conversion text of a semi-structured value, or null when the value is not one.
    static String
    The JSON text a client reads for a semi-structured value, or null when it holds no DOUBLE and the canonical text already is that text.
    static String
    doubleText(double value)
    One DOUBLE in the form the conversion uses: %.15e as C prints it, rounded from the double's exact binary value.
    static boolean
    Whether a column's declared type is one whose cells a client reads as JSON text.
    static String
    render(tools.jackson.databind.JsonNode node)
    One node's conversion text.
    static String
    The text of a semi-structured value under the STRING conversions — ::VARCHAR, TO_VARCHAR, TO_CHAR — which differs from TO_JSON's in one place: a value that IS a double and nothing more converts to a FLOAT's text rather than the fifteen-decimal one (live-verified cell by cell).
    static String
    The client text of a DOUBLE read out of a semi-structured value, or null when value is not one.
    static String
    The client text of a STRING read out of a semi-structured value: its JSON text, quotes included, as the account's driver hands every VARIANT cell back ("v" for OBJECT_CONSTRUCT('k', 'v'):k).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • convertedTextOf

      public static String convertedTextOf(Object value)
      The conversion text of a semi-structured value, or null when the value is not one.
      Parameters:
      value - any runtime value
      Returns:
      the JSON text live converts it to, or null when this rule does not apply
    • displayTextOf

      public static String displayTextOf(VariantValue value)
      The JSON text a client reads for a semi-structured value, or null when it holds no DOUBLE and the canonical text already is that text. Every DOUBLE takes the conversion form, a whole value as much as a member: live displays TO_VARIANT(1.5::FLOAT) as 1.500000000000000e+00 and ARRAY_CONSTRUCT(1.0::FLOAT) as [1.000000000000000e+00]. A VECTOR keeps its own text, since no display of one inside a VARIANT has been measured.
      Parameters:
      value - the value
      Returns:
      its display JSON text, or null when that is the canonical text
    • clientTextOf

      public static String clientTextOf(VariantValue value)
      The JSON text a client reads for a semi-structured value: displayTextOf(dev.frostlake.values.VariantValue), or the canonical text when there is no DOUBLE in it.
      Parameters:
      value - the value
      Returns:
      its client JSON text
    • unwrappedDoubleText

      public static String unwrappedDoubleText(Object value, DataType declared)
      The client text of a DOUBLE read out of a semi-structured value, or null when value is not one. An element or a path result arrives unwrapped, a Double under its VARIANT column, and the account still spells it as the VARIANT it is: the fifteen-decimal form, a non-finite value as its bare word.
      Parameters:
      value - any runtime value
      declared - the column's declared type
      Returns:
      its client text, or null when this rule does not apply
    • isSemiStructured

      public static boolean isSemiStructured(DataType declared)
      Whether a column's declared type is one whose cells a client reads as JSON text.
    • unwrappedStringText

      public static String unwrappedStringText(String value)
      The client text of a STRING read out of a semi-structured value: its JSON text, quotes included, as the account's driver hands every VARIANT cell back ("v" for OBJECT_CONSTRUCT('k', 'v'):k). The engine carries a JSON null unwrapped as the bare text null, and a string whose content could pass for structure or for that null already in its quotes; both are their own JSON text.
      Parameters:
      value - an unwrapped string under a semi-structured column
      Returns:
      its JSON text
    • stringConversionTextOf

      public static String stringConversionTextOf(Object value)
      The text of a semi-structured value under the STRING conversions — ::VARCHAR, TO_VARCHAR, TO_CHAR — which differs from TO_JSON's in one place: a value that IS a double and nothing more converts to a FLOAT's text rather than the fifteen-decimal one (live-verified cell by cell). A double that came from a FLOAT through TO_VARIANT takes the shortest round-trip form held to ten significant digits and one more per decade (1.5, 3.0, 1.0E18, -0.0, 1.414213562 for SQRT(2)); a double read from JSON text takes the FLOAT text (100 for 1e2, 1e+18, 1e-07, -0). A double INSIDE a container stays in the conversion form ([1.500000000000000e+00]), as does TO_JSON of the bare double.
      Parameters:
      value - any runtime value
      Returns:
      the text, or null when the value is not semi-structured or needs no rewriting
    • render

      public static String render(tools.jackson.databind.JsonNode node)
      One node's conversion text.
      Parameters:
      node - the parsed document
      Returns:
      its JSON text with every DOUBLE rewritten
    • doubleText

      public static String doubleText(double value)
      One DOUBLE in the form the conversion uses: %.15e as C prints it, rounded from the double's exact binary value. Java's formatter pads the shortest decimal representation instead, which differs wherever that representation is shorter than the value's sixteen digits: the smallest subnormal, 4.9E-324, is 4.940656458412465e-324 on the account.
      Parameters:
      value - the double
      Returns:
      its fifteen-decimal scientific text