Package org.apache.drill.common
Class Typifier
java.lang.Object
org.apache.drill.common.Typifier
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> boolean
contains
(T[] target, T source) Checks if a target array contains the source term.static boolean
containsAny
(CharSequence target, char[] source) static boolean
containsAny
(CharSequence target, CharSequence source) Returns true if any of the source characters are found in the target.static LocalDate
stringAsDate
(String date) Helper function that attempts to parse a String as a LocalDateTime.static LocalDateTime
stringAsDateTime
(String date) Helper function that attempts to parse a String as a LocalDateTime.Attempts to classify String input as double, int, char, etc.Attempts to determine the best data type for an unknown bit of text.
-
Constructor Details
-
Typifier
public Typifier()
-
-
Method Details
-
typify
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 stringbool01
- True, if you want 0/1 to be marked as boolean, false if notcommonTypes
- Limit typifier to boolean, double, string, timestamppostfixFL
- Allow typifier to consider f/F/l/L postfixes for float and longsparseDates
- Attempt to parse timestamps- Returns:
- An
Map.Entry
consisting of the object class and the original value as a String
-
stringAsDateTime
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
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
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
-
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 arraysource
- The source term- Returns:
- True if the target array contains the source term, false if not
-