Class ImpliedTextNumber

java.lang.Object
dev.frostlake.executor.expressions.ImpliedTextNumber

public final class ImpliedTextNumber extends Object
How a TEXT reads as a number in exact arithmetic — t + 0, t * n, MOD(t, 2), ROUND(t, 1) — live-verified over VARCHAR columns of every declared length and over literals:
  • a text COLUMN or expression reads as NUMBER(18,5): t + 0 declares NUMBER(19,5) and answers 5.00000, t / 1 NUMBER(24,11), t % 2 NUMBER(18,5); the value is rounded HALF_UP to five decimals before the operation ('1.123456' + 0 is 1.12346);
  • a text LITERAL reads as NUMBER(18, s) with ITS OWN scale: '5' + 1 declares NUMBER(19,0) and answers 6, '2.5' + 1 NUMBER(19,1) and 3.5, MOD('5', 2) NUMBER(2,0);
  • text beside text, beside a FLOAT, beside a VARIANT or beside a bare NULL is a FLOAT, as is a VARIANT beside anything and a signed text — those are not this reading.

The reading refuses at row time: a text spelling no number is Numeric value 'x' is not recognized; so is one whose five-decimal reading overflows the eighteen digits the account parses it into (an unscaled value past 9223372036854775807 — '99999999999999', '123456789012345', '1e14', '1e30'); one that parses but carries more than thirteen whole digits is Numeric value '12345678901234' is out of range — so is '1e13' and '9999999999999.999995', which rounds up to fourteen. Spellings a literal has are all read: ' 5 ', '.5', '5.', '+5', '5e2', '0000000000000005'.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final NumericType
    The number a text column reads as in exact arithmetic.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    Whether an expression is a text literal, whose reading keeps its own scale.
    The number a text literal reads as under the remainder operator and MOD: its own digits, as a numeric literal of the same spelling would — '5' NUMBER(1,0), '12345' NUMBER(5,0), '2.5' NUMBER(2,1) — or null when the text spells no number.
    The number a text LITERAL reads as: eighteen digits at the literal's own scale, or null when the text spells no number (the row-time refusal is then the operation's own).
    static BigDecimal
    A text column's value read as NUMBER(18,5), or the row-time refusal.

    Methods inherited from class java.lang.Object

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

    • COLUMN_READING

      public static final NumericType COLUMN_READING
      The number a text column reads as in exact arithmetic.
  • Method Details

    • literalReading

      public static NumericType literalReading(String text)
      The number a text LITERAL reads as: eighteen digits at the literal's own scale, or null when the text spells no number (the row-time refusal is then the operation's own).
      Parameters:
      text - the literal's text
      Returns:
      NUMBER(18, s), or null
    • literalOwnWidth

      public static NumericType literalOwnWidth(String text)
      The number a text literal reads as under the remainder operator and MOD: its own digits, as a numeric literal of the same spelling would — '5' NUMBER(1,0), '12345' NUMBER(5,0), '2.5' NUMBER(2,1) — or null when the text spells no number.
      Parameters:
      text - the literal's text
      Returns:
      the literal's own width, or null
    • isTextLiteral

      public static boolean isTextLiteral(Expression expr)
      Whether an expression is a text literal, whose reading keeps its own scale.
      Parameters:
      expr - the operand
      Returns:
      true for a quoted string literal
    • read

      public static BigDecimal read(CharSequence text)
      A text column's value read as NUMBER(18,5), or the row-time refusal.
      Parameters:
      text - the cell
      Returns:
      the value at scale five