Beispiel #1
0
def test_trivial_commands():
    assert parse_bql_string('''
        create population satellites for satellites_ucs (
            MODEL country_of_operator, orbit_type AS categorical;
            MODEL launch_mass AS numerical;
            MODEL perigee AS numerical;
            MODEL apogee, period AS numerical
        )
    ''') == \
        [ast.CreatePop(False, 'satellites', 'satellites_ucs', [
            ast.PopModelVars(
                ['country_of_operator', 'orbit_type'], 'categorical'),
            ast.PopModelVars(['launch_mass'], 'numerical'),
            ast.PopModelVars(['perigee'], 'numerical'),
            ast.PopModelVars(['apogee', 'period'], 'numerical'),
        ])]
    assert parse_bql_string('drop population satellites') == \
        [ast.DropPop(False, 'satellites')]
    assert parse_bql_string('create generator t_cc for t using crosscat'
            '(xyz numerical, pqr categorical, lmn cyclic)') == \
        [ast.CreateGen('t_cc', False, 't', None, 'crosscat', [
            ['xyz', 'numerical'],
            ['pqr', 'categorical'],
            ['lmn', 'cyclic'],
        ])]
    assert parse_bql_string('create generator t_cc for t with baseline crosscat'
            '(xyz numerical, pqr categorical, lmn cyclic)') == \
        [ast.CreateGen(
            't_cc', False, 't',
            ast.Baseline('crosscat', []),
            None,       # Defaults to cgpm.
            [
                ['xyz', 'numerical'],
                ['pqr', 'categorical'],
                ['lmn', 'cyclic'],
        ])]
    assert parse_bql_string('create generator t_cc if not exists'
            ' for t using crosscat'
            '(xyz numerical, pqr categorical, lmn cyclic)') == \
        [ast.CreateGen('t_cc', True, 't', None, 'crosscat', [
            ['xyz', 'numerical'],
            ['pqr', 'categorical'],
            ['lmn', 'cyclic'],
        ])]
    assert parse_bql_string('create generator if not exists t_cc'
            ' for t using crosscat'
            '(xyz numerical, pqr categorical, lmn cyclic)') == \
        [ast.CreateGen('t_cc', True, 't', None, 'crosscat', [
            ['xyz', 'numerical'],
            ['pqr', 'categorical'],
            ['lmn', 'cyclic'],
        ])]
    # XXX Schema of [[]] instead of [] is kinda wacky.  Fix?  (But
    # make sure the empty-parens and no-parens cases are equivalent.)
    assert parse_bql_string('create generator t_cc'
            ' for t using crosscat()') == \
        [ast.CreateGen('t_cc', False, 't', None, 'crosscat', [[]])]
    assert parse_bql_string('create generator t_cc'
            ' for t using crosscat') == \
        [ast.CreateGen('t_cc', False, 't', None, 'crosscat', [[]])]
    assert parse_bql_string('initialize 1 model for t;') == \
        [ast.InitModels(False, 't', 1)]
    assert parse_bql_string('initialize 1 model if not exists for t;') == \
        [ast.InitModels(True, 't', 1)]
    assert parse_bql_string('initialize 2 models for t;') == \
        [ast.InitModels(False, 't', 2)]
    assert parse_bql_string('initialize 2 models if not exists for t;') == \
        [ast.InitModels(True, 't', 2)]
    assert parse_bql_string('create temporary table tx as'
            ' infer explicit x, predict x as xi confidence xc from t_cc') == \
        [ast.CreateTabAs(True, False, 'tx',
            ast.InferExplicit(
                [
                    ast.SelColExp(ast.ExpCol(None, 'x'), None),
                    ast.PredCol('x', 'xi', 'xc', None),
                ],
                't_cc', None, None, None, None, None,
            ))]
Beispiel #2
0
 def p_baseline_opt_some(self, baseline, params):
     return ast.Baseline(name=baseline, params=params)