Class Filtex

java.lang.Object
net.hydromatic.filtex.Filtex

public class Filtex extends Object
Filter expressions.

Based on the @looker/filter-expressions TypeScript API.

  • Method Summary

    Modifier and Type
    Method
    Description
    static TypeFamily
    getExpressionType(boolean numeric, String type)
    Returns a valid filter expression type when given the type and field properties of a dashboard filter.
    static void
    Converts an AST to a single item for use in a token (i.e.
    static AstNode
    parseFilterExpression(TypeFamily typeFamily, String expression)
    Returns an Abstract Syntax Tree (AST) that logically represents the filter expression string passed in, as well as the filter expression type (and optional user attributes).
    static String
    summary(TypeFamily typeFamily, String s, Locale locale)
    Returns a localized, human-readable summary of a filter expression, given the expression's type, the expression itself, and the user attributes and field, if applicable.
    static void
    Returns an object with utility functions and values pertaining to a given expression type: toString: a function that converts an AST into an expression of the given type subTypes: an array containing the sub-types of the expression type, for example ">", "<", "=", "between" for a number expression type

    Methods inherited from class java.lang.Object

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

    • getExpressionType

      public static TypeFamily getExpressionType(boolean numeric, String type)
      Returns a valid filter expression type when given the type and field properties of a dashboard filter.

      For example,

      
       getExpressionType(true, "field_filter")
       

      returns TypeFamily.NUMBER.

    • parseFilterExpression

      public static AstNode parseFilterExpression(TypeFamily typeFamily, String expression)
      Returns an Abstract Syntax Tree (AST) that logically represents the filter expression string passed in, as well as the filter expression type (and optional user attributes).

      For example,

      
       parseFilterExpression(TypeFamily.NUMBER, "[0,20],>30")
       

      returns

      
       {
          type: ',',
          left: {
            type: 'between',
            bounds: '[]',
            low: 0,
            high: 20,
            is: true,
          },
          right: {
            is: true,
            type: '>',
            value: [30],
          },
       }
       
    • summary

      public static String summary(TypeFamily typeFamily, String s, Locale locale)
      Returns a localized, human-readable summary of a filter expression, given the expression's type, the expression itself, and the user attributes and field, if applicable.

      For example,

      
       summary(TypeFamily.NUMBER, "[0,20],>30", Locale.EN_US)
       

      returns "is in range [0, 20] or is > 30".

    • typeToGrammar

      public static void typeToGrammar()
      Returns an object with utility functions and values pertaining to a given expression type:
      • toString: a function that converts an AST into an expression of the given type
      • subTypes: an array containing the sub-types of the expression type, for example ">", "<", "=", "between" for a number expression type
    • getFilterTokenItem

      public static void getFilterTokenItem()
      Converts an AST to a single item for use in a token (i.e. not advanced) filter.