Class NumericLiteralTypes

java.lang.Object
dev.frostlake.types.NumericLiteralTypes

public final class NumericLiteralTypes extends Object
The NUMBER(precision, scale) Snowflake gives a numeric LITERAL.

Measured on a real account by declaring each literal into a table and reading INFORMATION_SCHEMA back: 1.5 and 0.5 are NUMBER(2,1), 0.05 NUMBER(3,2), 100.25 NUMBER(5,2), 1 NUMBER(1,0), 100 NUMBER(3,0), 0.0000000001 NUMBER(11,10) and 12345678901234567890 NUMBER(20,0). Trailing zeros do not count — 1.50 is NUMBER(2,1) and 0.000 is NUMBER(1,0), storing plain 0 — and an exponent is folded in before measuring, so 1.5e2 is NUMBER(3,0) holding 150. A leading . behaves as a zero integer part: .5 is NUMBER(2,1). The sign is not a digit: -1.5 is NUMBER(2,1).

So: normalise, take the scale (never negative), and add the integer digits with a floor of one — a value below 1 still reports the leading zero that 0.05 -> NUMBER(3,2) shows.

This matters beyond metadata. The inferred type becomes a derived relation's real column type, so a scale-0 NUMBER there does not merely misreport 0.05 — it STORES it as 0.

  • Method Summary

    Modifier and Type
    Method
    Description
    static BigDecimal
    The exact value a numeric literal's SOURCE TEXT stands for, in plain notation.
    static boolean
    Whether an exact value needs MORE digits than a NUMBER can hold, which is what takes a literal out of the fixed-point family altogether: live answers 1e37 as NUMBER(38,0) and 1e38 — one digit wider — as a DOUBLE, and does the same for the point spelling at thirty-nine digits.
    The NUMBER type of an exact decimal value.
    of(Object value)
    The NUMBER type of a numeric literal value, or null when it is not one we can measure.

    Methods inherited from class java.lang.Object

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

    • of

      public static NumericType of(Object value)
      The NUMBER type of a numeric literal value, or null when it is not one we can measure.
    • exactValue

      public static BigDecimal exactValue(String text)
      The exact value a numeric literal's SOURCE TEXT stands for, in plain notation.

      An exponent is a way of WRITING a fixed-point number, not a floating-point marker: live prints 1e20 back as 100000000000000000000 and 1e-3 as 0.001. BigDecimal keeps a negative scale for the first of those and would render it as 1E+20, so the scale is raised to zero — the value is unchanged and only its spelling becomes the one live uses.

      Parameters:
      text - the literal exactly as written
      Returns:
      its value
    • forDecimal

      public static NumericType forDecimal(BigDecimal value)
      The NUMBER type of an exact decimal value.
    • exceedsExactRange

      public static boolean exceedsExactRange(BigDecimal value)
      Whether an exact value needs MORE digits than a NUMBER can hold, which is what takes a literal out of the fixed-point family altogether: live answers 1e37 as NUMBER(38,0) and 1e38 — one digit wider — as a DOUBLE, and does the same for the point spelling at thirty-nine digits. The notation decides nothing; only the magnitude does.

      Trailing zeros are stripped first, for the reason forDecimal(java.math.BigDecimal) strips them: a literal written 99…9.0 with thirty-eight nines is a thirty-eight digit number, and counting its dropped .0 would push it over a boundary live keeps it inside.

      Parameters:
      value - the literal's exact value
      Returns:
      whether it is past the exact range