Class BinaryType

java.lang.Object
dev.frostlake.types.DataType
dev.frostlake.types.BinaryType
All Implemented Interfaces:
Serializable

public class BinaryType extends DataType
The BINARY family. Snowflake reports both spellings as the type BINARY everywhere a type is named — DESCRIBE, INFORMATION_SCHEMA, GET_DDL, a result column and even an argument-type refusal all say BINARY(8) for a VARBINARY column — so the NAME here is always BINARY and the spelling survives as isFixed(), which one metadata cell reads: SHOW COLUMNS' fixed flag.
See Also:
  • Field Details

    • DEFAULT_WIDTH

      public static final int DEFAULT_WIDTH
      The width a bare BINARY column declares, and the one a stored column settles a wider binary at.
      See Also:
    • NOMINAL_MAXIMUM

      public static final int NOMINAL_MAXIMUM
      The 64MB maximum an unsized binary is named at in a refusal.
      See Also:
    • BINARY

      public static BinaryType BINARY
    • VARBINARY

      public static BinaryType VARBINARY
    • UNSIZED

      public static final BinaryType UNSIZED
      The binary no width was given to: TO_BINARY's, a cast to a bare VARBINARY's, the crypto family's.
    • AT_MAXIMUM

      public static final BinaryType AT_MAXIMUM
      A binary sized at the 64MB maximum, held at the default width like every other.
  • Constructor Details

    • BinaryType

      public BinaryType(String name, int maxLength)
      A binary of that width, taking its fixedness from the SPELLING it was declared with. Both spellings are kept as an input vocabulary — the parser, the cast targets and the derived widths all name one — while the type they build reports BINARY either way.
      Parameters:
      name - the spelling, BINARY or VARBINARY
      maxLength - the declared width
    • BinaryType

      public BinaryType(int maxLength, boolean fixed)
      A binary of that width with its fixedness stated outright, which is what a restored snapshot and a fold both need — neither has a spelling to read it off.
      Parameters:
      maxLength - the declared width
      fixed - whether SHOW COLUMNS reports it fixed
    • BinaryType

      public BinaryType(int maxLength, boolean fixed, BinaryWidthSpelling widthSpelling)
      A binary held at that width whose width the plan spells as widthSpelling says.
      Parameters:
      maxLength - the width the binary is held at
      fixed - whether SHOW COLUMNS reports it fixed
      widthSpelling - how SYSTEM$TYPEOF and a refusal name its width
  • Method Details

    • getMaxLength

      public int getMaxLength()
    • getWidthSpelling

      public BinaryWidthSpelling getWidthSpelling()
      How this binary's width is spelled — see BinaryWidthSpelling.
    • typeofText

      public String typeofText()
      The type as SYSTEM$TYPEOF names it: bare BINARY when unsized, else with its width.
    • refusalText

      public String refusalText()
      The type as an argument-type refusal names it: an unsized binary at the 64MB maximum.
    • piece

      public BinaryType piece()
      The binary a piece of this one declares — SUBSTR, LEFT, RIGHT: this one's own width, and the maximum where this one is unsized (live: SUBSTR(b5, 1, 1) is BINARY(5), SUBSTR(TO_BINARY(s), 1, 1) BINARY(67108864)).
    • concatenation

      public static BinaryType concatenation(long sizedWidths, boolean unsizedOperand)
      The binary a concatenation declares, from its operands' SIZED widths added up and whether any operand is unsized or at the maximum. The widths add up to the 64MB maximum — live types two 8MB columns concatenated as BINARY(16777216) and an 8MB one beside a BINARY(5) as BINARY(8388613) — and a sum past it, or one over an unsized operand, is unsized itself: live, both X'00' || TO_BINARY('00') and CAST(x AS BINARY(67108864)) || X'00' read bare BINARY. Only a stored column settles the width (see atColumnWidth()). Never the fixed spelling: live reads a concatenation fixed false even over two BINARY columns.
      Parameters:
      sizedWidths - the sized operands' widths, added up
      unsizedOperand - whether any operand is unsized or at the maximum
      Returns:
      the concatenation's type
    • atColumnWidth

      public BinaryType atColumnWidth()
      This binary as a stored column holds it: a width past DEFAULT_WIDTH settles at that default, keeping its fixedness. Live stores a CTAS over a 16MB concatenation, or over CAST(x AS BINARY(67108864)), as BINARY(8388608), and declares a view's such column the same while a query over the view still reads the full width. A binary within the default is itself.
      Returns:
      the binary a stored column takes
    • isFixed

      public boolean isFixed()
      Whether this binary is the FIXED spelling, which is the whole meaning of SHOW COLUMNS' fixed cell. The flag is not "this is a BINARY" — every binary reports the type BINARY. It says the type was spelled BINARY rather than arrived at some other way (live-verified):
         BINARY / BINARY(4) column      true      VARBINARY(4) column            false
         CAST(x AS BINARY(10))          true      CAST(x AS VARBINARY(10))       false
         CAST(bin || bin AS BINARY)     true      bin || bin, CONCAT(bin, bin)   false
                                                  every binary-returning function
                                                  an X'..' literal
       

      So a CAST to BINARY RESETS it — being derived is not what makes it false — and no function ever produces it, TO_BINARY included, which is the pair worth remembering: TO_BINARY(s) and CAST(s AS BINARY) convert identically and differ only in this cell.

      Returns:
      true when the type was spelled BINARY
    • parseValue

      public Object parseValue(String value)
      Specified by:
      parseValue in class DataType
    • formatValue

      public String formatValue(Object value)
      Specified by:
      formatValue in class DataType
    • isCompatible

      public boolean isCompatible(DataType other)
      Specified by:
      isCompatible in class DataType
    • getCommonType

      public DataType getCommonType(DataType other)
      Specified by:
      getCommonType in class DataType
    • getSize

      public int getSize()
      Specified by:
      getSize in class DataType
    • unsized

      public static BinaryType unsized(boolean fixed)
      The unsized binary of a cast to a bare BINARY (fixed) or VARBINARY.