Ejemplo n.º 1
0
 def p_equality_notglob(self, l, r): return ast.op(ast.OP_NOTGLOB, l, r)
 def p_equality_glob_esc(self, l, r, e):
Ejemplo n.º 2
0
 def p_multiplicative_mul(self, l, r):
     return ast.op(ast.OP_MUL, l, r)
Ejemplo n.º 3
0
 def p_unary_bitwise_not(self, u):
     return ast.op(ast.OP_BITNOT, u)
Ejemplo n.º 4
0
 def p_ordering_leq(self, l, r):
     return ast.op(ast.OP_LEQ, l, r)
Ejemplo n.º 5
0
 def p_bitwise_ior(self, l, r):
     return ast.op(ast.OP_BITIOR, l, r)
Ejemplo n.º 6
0
 def p_equality_notmatch(self, l, r):
     return ast.op(ast.OP_NOTMATCH, l, r)
Ejemplo n.º 7
0
 def p_equality_isnull(self, e):
     return ast.op(ast.OP_ISNULL, e)
Ejemplo n.º 8
0
 def p_equality_between(self, m, l, r):
                                     return ast.op(ast.OP_BETWEEN, m, l, r)
Ejemplo n.º 9
0
 def p_equality_notbetween(self, m, l, r):
                                     return ast.op(ast.OP_NOTBETWEEN, m,l,r)
Ejemplo n.º 10
0
 def p_equality_notmatch(self, l, r):
                                     return ast.op(ast.OP_NOTMATCH, l, r)
Ejemplo n.º 11
0
 def p_equality_notmatch_esc(self, l, r, e):
                                     return ast.op(ast.OP_NOTMATCH_ESC,
                                         l, r, e)
Ejemplo n.º 12
0
 def p_equality_notregexp_esc(self, l, r, e):
                                     return ast.op(ast.OP_NOTREGEXP_ESC,
                                         l, r, e)
Ejemplo n.º 13
0
 def p_equality_notregexp(self, l, r):
                                     return ast.op(ast.OP_NOTREGEXP, l, r)
Ejemplo n.º 14
0
 def p_equality_notglob_esc(self, l, r, e):
                                     return ast.op(ast.OP_NOTGLOB_ESC,
                                         l, r, e)
Ejemplo n.º 15
0
 def p_equality_regexp(self, l, r):
     return ast.op(ast.OP_REGEXP, l, r)
Ejemplo n.º 16
0
 def p_equality_isnull(self, e):     return ast.op(ast.OP_ISNULL, e)
 def p_equality_notnull(self, e):    return ast.op(ast.OP_NOTNULL, e)
Ejemplo n.º 17
0
 def p_equality_notregexp_esc(self, l, r, e):
     return ast.op(ast.OP_NOTREGEXP_ESC, l, r, e)
Ejemplo n.º 18
0
 def p_equality_notnull(self, e):    return ast.op(ast.OP_NOTNULL, e)
 def p_equality_neq(self, l, r):     return ast.op(ast.OP_NEQ, l, r)
Ejemplo n.º 19
0
 def p_equality_between(self, m, l, r):
     return ast.op(ast.OP_BETWEEN, m, l, r)
Ejemplo n.º 20
0
 def p_equality_neq(self, l, r):     return ast.op(ast.OP_NEQ, l, r)
 def p_equality_eq(self, l, r):      return ast.op(ast.OP_EQ, l, r)
Ejemplo n.º 21
0
 def p_equality_eq(self, l, r):
     return ast.op(ast.OP_EQ, l, r)
Ejemplo n.º 22
0
 def p_equality_eq(self, l, r):      return ast.op(ast.OP_EQ, l, r)
 def p_equality_ordering(self, o):   return o
Ejemplo n.º 23
0
 def p_ordering_gt(self, l, r):
     return ast.op(ast.OP_GT, l, r)
Ejemplo n.º 24
0
 def p_ordering_lt(self, l, r):      return ast.op(ast.OP_LT, l, r)
 def p_ordering_leq(self, l, r):     return ast.op(ast.OP_LEQ, l, r)
Ejemplo n.º 25
0
 def p_additive_add(self, l, r):
     return ast.op(ast.OP_ADD, l, r)
Ejemplo n.º 26
0
 def p_ordering_geq(self, l, r):     return ast.op(ast.OP_GEQ, l, r)
 def p_ordering_gt(self, l, r):      return ast.op(ast.OP_GT, l, r)
Ejemplo n.º 27
0
 def p_multiplicative_rem(self, l, r):
     return ast.op(ast.OP_REM, l, r)
Ejemplo n.º 28
0
 def p_ordering_gt(self, l, r):      return ast.op(ast.OP_GT, l, r)
 def p_ordering_bitwise(self, b):    return b
Ejemplo n.º 29
0
 def p_unary_plus(self, u):
     return ast.op(ast.OP_PLUSID, u)
Ejemplo n.º 30
0
 def p_bitwise_and(self, l, r):      return ast.op(ast.OP_BITAND, l, r)
 def p_bitwise_ior(self, l, r):      return ast.op(ast.OP_BITIOR, l, r)
Ejemplo n.º 31
0
 def p_equality_notglob_esc(self, l, r, e):
     return ast.op(ast.OP_NOTGLOB_ESC, l, r, e)
Ejemplo n.º 32
0
 def p_bitwise_ior(self, l, r):      return ast.op(ast.OP_BITIOR, l, r)
 def p_bitwise_lshift(self, l, r):   return ast.op(ast.OP_LSHIFT, l, r)
Ejemplo n.º 33
0
 def p_equality_notregexp(self, l, r):
     return ast.op(ast.OP_NOTREGEXP, l, r)
Ejemplo n.º 34
0
 def p_bitwise_lshift(self, l, r):   return ast.op(ast.OP_LSHIFT, l, r)
 def p_bitwise_rshift(self, l, r):   return ast.op(ast.OP_RSHIFT, l, r)
Ejemplo n.º 35
0
 def p_equality_match(self, l, r):
     return ast.op(ast.OP_MATCH, l, r)
Ejemplo n.º 36
0
 def p_bitwise_rshift(self, l, r):   return ast.op(ast.OP_RSHIFT, l, r)
 def p_bitwise_additive(self, a):    return a
Ejemplo n.º 37
0
 def p_equality_notmatch_esc(self, l, r, e):
     return ast.op(ast.OP_NOTMATCH_ESC, l, r, e)
Ejemplo n.º 38
0
 def p_additive_add(self, l, r):     return ast.op(ast.OP_ADD, l, r)
 def p_additive_sub(self, l, r):     return ast.op(ast.OP_SUB, l, r)
Ejemplo n.º 39
0
 def p_equality_notbetween(self, m, l, r):
     return ast.op(ast.OP_NOTBETWEEN, m, l, r)
Ejemplo n.º 40
0
 def p_additive_sub(self, l, r):     return ast.op(ast.OP_SUB, l, r)
 def p_additive_mult(self, m):       return m
Ejemplo n.º 41
0
 def p_equality_notnull(self, e):
     return ast.op(ast.OP_NOTNULL, e)
Ejemplo n.º 42
0
 def p_multiplicative_mul(self, l, r):
                                     return ast.op(ast.OP_MUL, l, r)
Ejemplo n.º 43
0
 def p_ordering_lt(self, l, r):
     return ast.op(ast.OP_LT, l, r)
Ejemplo n.º 44
0
 def p_multiplicative_div(self, l, r):
                                     return ast.op(ast.OP_DIV, l, r)
Ejemplo n.º 45
0
 def p_ordering_geq(self, l, r):
     return ast.op(ast.OP_GEQ, l, r)
Ejemplo n.º 46
0
 def p_multiplicative_rem(self, l, r):
                                     return ast.op(ast.OP_REM, l, r)
Ejemplo n.º 47
0
 def p_bitwise_and(self, l, r):
     return ast.op(ast.OP_BITAND, l, r)
Ejemplo n.º 48
0
 def p_concatenative_concat(self, l, r):
                                     return ast.op(ast.OP_CONCAT, l, r)
Ejemplo n.º 49
0
 def p_bitwise_rshift(self, l, r):
     return ast.op(ast.OP_RSHIFT, l, r)
Ejemplo n.º 50
0
 def p_unary_bitwise_not(self, u):   return ast.op(ast.OP_BITNOT, u)
 def p_unary_minus(self, u):         return ast.op(ast.OP_NEGATE, u)
Ejemplo n.º 51
0
 def p_additive_sub(self, l, r):
     return ast.op(ast.OP_SUB, l, r)
Ejemplo n.º 52
0
 def p_unary_minus(self, u):         return ast.op(ast.OP_NEGATE, u)
 def p_unary_plus(self, u):          return ast.op(ast.OP_PLUSID, u)
Ejemplo n.º 53
0
 def p_multiplicative_div(self, l, r):
     return ast.op(ast.OP_DIV, l, r)
Ejemplo n.º 54
0
 def p_unary_plus(self, u):          return ast.op(ast.OP_PLUSID, u)
 def p_unary_bql(self, b):           return b
Ejemplo n.º 55
0
 def p_concatenative_concat(self, l, r):
     return ast.op(ast.OP_CONCAT, l, r)
Ejemplo n.º 56
0
def test_select_bql():
    assert parse_bql_string('select predictive probability of c from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(ast.ExpBQLPredProb('c'), None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select predictive probability of c, * from t;') \
        == \
        [ast.Select(ast.SELQUANT_ALL,
            [
                ast.SelColExp(ast.ExpBQLPredProb('c'), None),
                ast.SelColAll(None),
            ],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select c, predictive probability of d from t;') \
        == \
        [ast.Select(ast.SELQUANT_ALL,
            [
                ast.SelColExp(ast.ExpCol(None, 'c'), None),
                ast.SelColExp(ast.ExpBQLPredProb('d'), None),
            ],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select predictive probability of c, d from t;') \
        == \
        [ast.Select(ast.SELQUANT_ALL,
            [
                ast.SelColExp(ast.ExpBQLPredProb('c'), None),
                ast.SelColExp(ast.ExpCol(None, 'd'), None),
            ],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select probability of c = 42 from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(ast.ExpBQLProb([('c', ast.ExpLit(ast.LitInt(42)))],
                    []),
                None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select similarity from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(ast.ExpBQLSim(None, [ast.ColListAll()]), None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select similarity to (rowid=8) from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(
                ast.ExpBQLSim(
                    ast.ExpOp(ast.OP_EQ, (
                        ast.ExpCol(None, 'rowid'),
                        ast.ExpLit(ast.LitInt(8))
                    )),
                    [ast.ColListAll()]),
                None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select similarity with respect to c from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(ast.ExpBQLSim(None, [ast.ColListLit(['c'])]),
                None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string(
            'select similarity to (rowid=8) with respect to c from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(
                ast.ExpBQLSim(
                    ast.ExpOp(ast.OP_EQ, (
                        ast.ExpCol(None, 'rowid'),
                        ast.ExpLit(ast.LitInt(8)),
                    )),
                    [ast.ColListLit(['c'])]),
                None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string(
            'select similarity to (rowid=5) with respect to age from t1;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(
                ast.ExpBQLSim(
                    ast.ExpOp(ast.OP_EQ, (
                        ast.ExpCol(None, 'rowid'),
                        ast.ExpLit(ast.LitInt(5)),
                    )),
                    [ast.ColListLit(['age'])]),
                None)],
            [ast.SelTab('t1', None)], None, None, None, None)]
    assert parse_bql_string(
            'select similarity to (rowid=8) with respect to c, d from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [
                ast.SelColExp(
                    ast.ExpBQLSim(
                        ast.ExpOp(ast.OP_EQ, (
                            ast.ExpCol(None, 'rowid'),
                            ast.ExpLit(ast.LitInt(8)),
                        )),
                        [ast.ColListLit(['c'])]),
                    None),
                ast.SelColExp(ast.ExpCol(None, 'd'), None),
            ],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select similarity to (rowid=8)'
            ' with respect to (c, d) from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(
                ast.ExpBQLSim(
                    ast.ExpOp(ast.OP_EQ, (
                        ast.ExpCol(None, 'rowid'),
                        ast.ExpLit(ast.LitInt(8)),
                    )),
                    [ast.ColListLit(['c']), ast.ColListLit(['d'])]),
                None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select similarity to (rowid=8) with respect to' +
            ' (estimate * from columns of t order by ' +
            '  probability of value 4 limit 1)' +
            ' from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(
                ast.ExpBQLSim(
                    ast.ExpOp(ast.OP_EQ, (
                        ast.ExpCol(None, 'rowid'),
                        ast.ExpLit(ast.LitInt(8)),
                    )),
                    [ast.ColListSub(
                        ast.EstCols([ast.SelColAll(None)], 't',
                            ast.ExpLit(ast.LitNull(None)),
                            None,
                            [ast.Ord(ast.ExpBQLProbFn(
                                    ast.ExpLit(ast.LitInt(4)),
                                    []),
                                ast.ORD_ASC)],
                            ast.Lim(ast.ExpLit(ast.LitInt(1)), None))
                    )]),
                None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select dependence probability with c from t;') ==\
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(ast.ExpBQLDepProb('c', None), None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string(
            'select dependence probability of c with d from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(ast.ExpBQLDepProb('c', 'd'), None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select mutual information with c from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(ast.ExpBQLMutInf('c', None, None), None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string(
            'select mutual information of c with d from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(ast.ExpBQLMutInf('c', 'd', None), None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select mutual information of c with d' +
            ' using (1+2) samples from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(ast.ExpBQLMutInf('c', 'd',
                    ast.op(ast.OP_ADD, ast.ExpLit(ast.LitInt(1)),
                        ast.ExpLit(ast.LitInt(2)))),
                None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select correlation with c from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(ast.ExpBQLCorrel('c', None), None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select correlation of c with d from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(ast.ExpBQLCorrel('c', 'd'), None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    # XXX This got broken a while ago: parenthesization in PROBABILITY
    # OF X = E is too permissive.  I didn't notice because before I
    # introduced BQLParseError, this simply caught Exception -- which
    # covered the AssertionError that this turned into.
    #
    # with pytest.raises(parse.BQLParseError):
    #     parse_bql_string('select probability of x = 1 -' +
    #         ' probability of y = 0 from t;')
    #     # XXX Should really be this test, but getting the grammar to
    #     # admit this unambiguously is too much of a pain at the
    #     # moment.
    #     assert parse_bql_string('select probability of x = 1 -' +
    #             ' probability of y = 0 from t;') == \
    #         [ast.Select(ast.SELQUANT_ALL,
    #             [ast.SelColExp(ast.ExpBQLProb([('x',
    #                         ast.ExpOp(ast.OP_SUB, (
    #                             ast.ExpLit(ast.LitInt(1)),
    #                             ast.ExpBQLProb([('y',
    #                                     ast.ExpLit(ast.LitInt(0)))],
    #                                 []),
    #                         )))],
    #                     []),
    #                 None)],
    #             [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select probability of c1 = f(c2) from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(ast.ExpBQLProb([('c1',
                        ast.ExpApp(False, 'f', [ast.ExpCol(None, 'c2')]))],
                    []),
                None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select key, t.(estimate * from columns of t'
            ' order by dependence probability with c desc limit 4)'
            ' from t order by key asc') == \
        [ast.Select(ast.SELQUANT_ALL, [
                ast.SelColExp(ast.ExpCol(None, 'key'), None),
                ast.SelColSub('t',
                    ast.EstCols([ast.SelColAll(None)], 't',
                        ast.ExpLit(ast.LitNull(None)), None,
                        [ast.Ord(ast.ExpBQLDepProb('c', None), ast.ORD_DESC)],
                        ast.Lim(ast.ExpLit(ast.LitInt(4)), None)))
            ],
            [ast.SelTab('t', None)],
            None, None,
            [ast.Ord(ast.ExpCol(None, 'key'), ast.ORD_ASC)],
            None)]
Ejemplo n.º 57
0
 def p_unary_minus(self, u):
     return ast.op(ast.OP_NEGATE, u)
Ejemplo n.º 58
0
 def p_equality_notglob(self, l, r):
     return ast.op(ast.OP_NOTGLOB, l, r)
Ejemplo n.º 59
0
def test_select_bql():
    assert parse_bql_string('select predictive probability of c from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(ast.ExpBQLPredProb('c'), None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select predictive probability of c, * from t;') \
        == \
        [ast.Select(ast.SELQUANT_ALL,
            [
                ast.SelColExp(ast.ExpBQLPredProb('c'), None),
                ast.SelColAll(None),
            ],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select c, predictive probability of d from t;') \
        == \
        [ast.Select(ast.SELQUANT_ALL,
            [
                ast.SelColExp(ast.ExpCol(None, 'c'), None),
                ast.SelColExp(ast.ExpBQLPredProb('d'), None),
            ],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select predictive probability of c, d from t;') \
        == \
        [ast.Select(ast.SELQUANT_ALL,
            [
                ast.SelColExp(ast.ExpBQLPredProb('c'), None),
                ast.SelColExp(ast.ExpCol(None, 'd'), None),
            ],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select probability of c = 42 from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(ast.ExpBQLProb([('c', ast.ExpLit(ast.LitInt(42)))],
                    []),
                None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select similarity from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(ast.ExpBQLSim(None, [ast.ColListAll()]), None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select similarity to (rowid=8) from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(
                ast.ExpBQLSim(
                    ast.ExpOp(ast.OP_EQ, (
                        ast.ExpCol(None, 'rowid'),
                        ast.ExpLit(ast.LitInt(8))
                    )),
                    [ast.ColListAll()]),
                None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select similarity with respect to c from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(ast.ExpBQLSim(None, [ast.ColListLit(['c'])]),
                None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string(
            'select similarity to (rowid=8) with respect to c from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(
                ast.ExpBQLSim(
                    ast.ExpOp(ast.OP_EQ, (
                        ast.ExpCol(None, 'rowid'),
                        ast.ExpLit(ast.LitInt(8)),
                    )),
                    [ast.ColListLit(['c'])]),
                None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string(
            'select similarity to (rowid=5) with respect to age from t1;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(
                ast.ExpBQLSim(
                    ast.ExpOp(ast.OP_EQ, (
                        ast.ExpCol(None, 'rowid'),
                        ast.ExpLit(ast.LitInt(5)),
                    )),
                    [ast.ColListLit(['age'])]),
                None)],
            [ast.SelTab('t1', None)], None, None, None, None)]
    assert parse_bql_string(
            'select similarity to (rowid=8) with respect to c, d from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [
                ast.SelColExp(
                    ast.ExpBQLSim(
                        ast.ExpOp(ast.OP_EQ, (
                            ast.ExpCol(None, 'rowid'),
                            ast.ExpLit(ast.LitInt(8)),
                        )),
                        [ast.ColListLit(['c'])]),
                    None),
                ast.SelColExp(ast.ExpCol(None, 'd'), None),
            ],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select similarity to (rowid=8)'
            ' with respect to (c, d) from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(
                ast.ExpBQLSim(
                    ast.ExpOp(ast.OP_EQ, (
                        ast.ExpCol(None, 'rowid'),
                        ast.ExpLit(ast.LitInt(8)),
                    )),
                    [ast.ColListLit(['c']), ast.ColListLit(['d'])]),
                None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select similarity to (rowid=8) with respect to' +
            ' (estimate * from columns of t order by ' +
            '  probability of value 4 limit 1)' +
            ' from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(
                ast.ExpBQLSim(
                    ast.ExpOp(ast.OP_EQ, (
                        ast.ExpCol(None, 'rowid'),
                        ast.ExpLit(ast.LitInt(8)),
                    )),
                    [ast.ColListSub(
                        ast.EstCols([ast.SelColAll(None)], 't', None, None,
                            [ast.Ord(ast.ExpBQLProbFn(
                                    ast.ExpLit(ast.LitInt(4)),
                                    []),
                                ast.ORD_ASC)],
                            ast.Lim(ast.ExpLit(ast.LitInt(1)), None))
                    )]),
                None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select dependence probability with c from t;') ==\
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(ast.ExpBQLDepProb('c', None), None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string(
            'select dependence probability of c with d from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(ast.ExpBQLDepProb('c', 'd'), None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select mutual information with c from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(ast.ExpBQLMutInf('c', None, None, None), None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string(
            'select mutual information of c with d from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(ast.ExpBQLMutInf('c', 'd', None, None), None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select mutual information of c with d' +
            ' using (1+2) samples from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(
                ast.ExpBQLMutInf(
                    'c', 'd', None,
                    ast.op(
                        ast.OP_ADD, ast.ExpLit(ast.LitInt(1)),
                        ast.ExpLit(ast.LitInt(2)))),
                None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('''
            select mutual information with c given (d, a=1) using
            10 samples from t;
            ''') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(
                ast.ExpBQLMutInf(
                    'c', None,
                    [('d', ast.ExpLit(ast.LitNull(0))),
                        ('a',ast.ExpLit(ast.LitInt(1)))],
                    ast.ExpLit(ast.LitInt(10))
                ),
            None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('''
            select mutual information of b with c
            given (d, a=1, e, r=2) from t;''') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(
                ast.ExpBQLMutInf(
                    'b', 'c',
                    [
                        ('d', ast.ExpLit(ast.LitNull(0))),
                        ('a',ast.ExpLit(ast.LitInt(1))),
                        ('e', ast.ExpLit(ast.LitNull(0))),
                        ('r', ast.ExpLit(ast.LitInt(2))),
                    ],
                    None
                ),
            None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select correlation with c from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(ast.ExpBQLCorrel('c', None), None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select correlation of c with d from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(ast.ExpBQLCorrel('c', 'd'), None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    # XXX This got broken a while ago: parenthesization in PROBABILITY
    # OF X = E is too permissive.  I didn't notice because before I
    # introduced BQLParseError, this simply caught Exception -- which
    # covered the AssertionError that this turned into.
    #
    # with pytest.raises(parse.BQLParseError):
    #     parse_bql_string('select probability of x = 1 -' +
    #         ' probability of y = 0 from t;')
    #     # XXX Should really be this test, but getting the grammar to
    #     # admit this unambiguously is too much of a pain at the
    #     # moment.
    #     assert parse_bql_string('select probability of x = 1 -' +
    #             ' probability of y = 0 from t;') == \
    #         [ast.Select(ast.SELQUANT_ALL,
    #             [ast.SelColExp(ast.ExpBQLProb([('x',
    #                         ast.ExpOp(ast.OP_SUB, (
    #                             ast.ExpLit(ast.LitInt(1)),
    #                             ast.ExpBQLProb([('y',
    #                                     ast.ExpLit(ast.LitInt(0)))],
    #                                 []),
    #                         )))],
    #                     []),
    #                 None)],
    #             [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select probability of c1 = f(c2) from t;') == \
        [ast.Select(ast.SELQUANT_ALL,
            [ast.SelColExp(ast.ExpBQLProb([('c1',
                        ast.ExpApp(False, 'f', [ast.ExpCol(None, 'c2')]))],
                    []),
                None)],
            [ast.SelTab('t', None)], None, None, None, None)]
    assert parse_bql_string('select key, t.(estimate * from columns of t'
            ' order by dependence probability with c desc limit 4)'
            ' from t order by key asc') == \
        [ast.Select(ast.SELQUANT_ALL, [
                ast.SelColExp(ast.ExpCol(None, 'key'), None),
                ast.SelColSub('t',
                    ast.EstCols([ast.SelColAll(None)], 't', None, None,
                        [ast.Ord(ast.ExpBQLDepProb('c', None), ast.ORD_DESC)],
                        ast.Lim(ast.ExpLit(ast.LitInt(4)), None)))
            ],
            [ast.SelTab('t', None)],
            None, None,
            [ast.Ord(ast.ExpCol(None, 'key'), ast.ORD_ASC)],
            None)]
Ejemplo n.º 60
0
 def p_equality_notlike_esc(self, l, r, e):
                                     return ast.op(ast.OP_NOTLIKE_ESC,
                                         l, r, e)