def datetime_parser() -> ParseResults: # pylint: disable=too-many-locals ( # pylint: disable=invalid-name DATETIME, DATEADD, DATETRUNC, LASTDAY, HOLIDAY, YEAR, QUARTER, MONTH, WEEK, DAY, HOUR, MINUTE, SECOND, ) = map( CaselessKeyword, "datetime dateadd datetrunc lastday holiday " "year quarter month week day hour minute second".split(), ) lparen, rparen, comma = map(Suppress, "(),") int_operand = pyparsing_common.signed_integer().setName("int_operand") text_operand = quotedString.setName("text_operand").setParseAction( EvalText) # allow expression to be used recursively datetime_func = Forward().setName("datetime") dateadd_func = Forward().setName("dateadd") datetrunc_func = Forward().setName("datetrunc") lastday_func = Forward().setName("lastday") holiday_func = Forward().setName("holiday") date_expr = (datetime_func | dateadd_func | datetrunc_func | lastday_func | holiday_func) datetime_func <<= (DATETIME + lparen + text_operand + rparen).setParseAction(EvalDateTimeFunc) dateadd_func <<= ( DATEADD + lparen + Group(date_expr + comma + int_operand + comma + (YEAR | QUARTER | MONTH | WEEK | DAY | HOUR | MINUTE | SECOND) + ppOptional(comma)) + rparen).setParseAction(EvalDateAddFunc) datetrunc_func <<= ( DATETRUNC + lparen + Group(date_expr + comma + (YEAR | MONTH | WEEK | DAY | HOUR | MINUTE | SECOND) + ppOptional(comma)) + rparen).setParseAction(EvalDateTruncFunc) lastday_func <<= (LASTDAY + lparen + Group(date_expr + comma + (YEAR | MONTH | WEEK) + ppOptional(comma)) + rparen).setParseAction(EvalLastDayFunc) holiday_func <<= (HOLIDAY + lparen + Group(text_operand + ppOptional(comma) + ppOptional(date_expr) + ppOptional(comma) + ppOptional(text_operand) + ppOptional(comma)) + rparen).setParseAction(EvalHolidayFunc) return date_expr
opAssoc, ) import great_expectations.exceptions as ge_exceptions from great_expectations.core.expectation_configuration import ExpectationConfiguration from great_expectations.rule_based_profiler.config import ParameterBuilderConfig from great_expectations.rule_based_profiler.expectation_configuration_builder import ( ExpectationConfigurationBuilder, ) from great_expectations.rule_based_profiler.helpers.util import ( get_parameter_value_and_validate_return_type, ) from great_expectations.rule_based_profiler.types import Domain, ParameterContainer text = Suppress("'") + Word(alphas, alphanums) + Suppress("'") integer = Word(nums).setParseAction(lambda t: int(t[0])) var = Combine( Word("$" + alphas, alphanums + "_.") + ppOptional("[" + integer + "]")) comparison_operator = oneOf(">= <= != > < ==") binary_operator = oneOf("~ & |") operand = text | integer | var expr = infixNotation( operand, [ (comparison_operator, 2, opAssoc.LEFT), (binary_operator, 2, opAssoc.LEFT), ], ) class ExpectationConfigurationConditionParserError( ge_exceptions.GreatExpectationsError):