Class Typifier

java.lang.Object
org.apache.drill.common.Typifier

public class Typifier extends Object
This class attempts to infer the data type of an unknown data type. It is somewhat configurable. This was sourced from this code on github.
  • Constructor Details

    • Typifier

      public Typifier()
  • Method Details

    • typify

      public static Map.Entry<Class,String> typify(String data)
      Attempts to classify String input as double, int, char, etc. Common types are: boolean, double, string, timestamp. This is the default constructor for the simplest use case. The defaults are not to interpet 0,1 as true/false, restrict interpretation to common types, not to allow f/F/l/L postfixes for float and longs and attempts to parse dates.
      Parameters:
      data - Input string of data
      Returns:
      An Entry of the Class and the original value
    • typify

      public static Map.Entry<Class,String> typify(String data, boolean bool01, boolean commonTypes, boolean postfixFL, boolean parseDates)
      Attempts to determine the best data type for an unknown bit of text. This constructor allows you to set a few
      Parameters:
      data - The unknown data string
      bool01 - True, if you want 0/1 to be marked as boolean, false if not
      commonTypes - Limit typifier to boolean, double, string, timestamp
      postfixFL - Allow typifier to consider f/F/l/L postfixes for float and longs
      parseDates - Attempt to parse timestamps
      Returns:
      An Map.Entry consisting of the object class and the original value as a String
    • stringAsDateTime

      public static LocalDateTime stringAsDateTime(String date)
      Helper function that attempts to parse a String as a LocalDateTime. If the string cannot be parsed, return null.
      Parameters:
      date - Input date string
      Returns:
      LocalDateTime representation of the input String.
    • stringAsDate

      public static LocalDate stringAsDate(String date)
      Helper function that attempts to parse a String as a LocalDateTime. If the string cannot be parsed, return null.
      Parameters:
      date - Input date string
      Returns:
      LocalDateTime representation of the input String.
    • containsAny

      public static boolean containsAny(CharSequence target, CharSequence source)
      Returns true if any of the source characters are found in the target.
      Parameters:
      target - The target character sequence AKA the haystack.
      source - The source characters, AKA the needle
      Returns:
      True if the needle is in the haystack, false if not
    • containsAny

      public static boolean containsAny(CharSequence target, char[] source)
    • contains

      public static <T> boolean contains(T[] target, T source)
      Checks if a target array contains the source term.
      Type Parameters:
      T - Unknown class
      Parameters:
      target - The target array
      source - The source term
      Returns:
      True if the target array contains the source term, false if not