Esempio n. 1
0
 def _sql(
     self, code: str, *args: Any, **kwargs: Any
 ) -> Dict[str, Tuple[WorkflowDataFrame, WorkflowDataFrames,
                      LazyWorkflowDataFrame]]:
     # TODO: move dict construction to triad
     params: Dict[str, Any] = {}
     for a in args:
         assert_or_throw(isinstance(a, Dict),
                         lambda: f"args can only have dict: {a}")
         params.update(a)
     params.update(kwargs)
     params, dfs = self._split_params(params)
     code = fill_sql_template(code, params)
     sql = FugueSQL(
         code,
         "fugueLanguage",
         ignore_case=self.conf.get_or_throw(FUGUE_SQL_CONF_IGNORE_CASE,
                                            bool),
         simple_assign=self.conf.get_or_throw(FUGUE_SQL_CONF_SIMPLE_ASSIGN,
                                              bool),
     )
     v = _Extensions(
         sql,
         FugueSQLHooks(),
         self,
         dfs,
         local_vars=params  # type: ignore
     )
     v.visit(sql.tree)
     return v.variables
Esempio n. 2
0
 def assert_eq(expr, expected=None):
     sql = FugueSQL(expr, "fugueWildSchema", ignore_case=True)
     v = _VisitorBase(sql)
     obj = v.visit(sql.tree)
     if expected is None:
         expected = expr
     assert expected == obj
Esempio n. 3
0
 def _sql(self, code: str, *args: Any,
          **kwargs: Any) -> Dict[str, WorkflowDataFrame]:
     # TODO: move dict construction to triad
     params: Dict[str, Any] = {}
     for a in args:
         assert_or_throw(isinstance(a, Dict),
                         f"args can only have dict: {a}")
         params.update(a)
     params.update(kwargs)
     code = fill_sql_template(code, params)
     sql = FugueSQL(
         code,
         "fugueLanguage",
         ignore_case=self.conf.get_or_throw("fugue.sql.compile.ignore_case",
                                            bool),
         simple_assign=self.conf.get_or_throw(
             "fugue.sql.compile.simple_assign", bool),
     )
     dfs = {
         k: v
         for k, v in params.items() if isinstance(v, WorkflowDataFrame)
     }
     v = _Extensions(sql, FugueSQLHooks(), self, dfs)
     v.visit(sql.tree)
     return v.variables
Esempio n. 4
0
 def _sql(self, code: str, *args: Any,
          **kwargs: Any) -> Dict[str, WorkflowDataFrame]:
     # TODO: move dict construction to triad
     params: Dict[str, Any] = {}
     for a in args:
         assert_or_throw(isinstance(a, Dict),
                         f"args can only have dict: {a}")
         params.update(a)
     params.update(kwargs)
     template_params = dict(params)
     if "self" in template_params:
         del template_params["self"]
     code = fill_sql_template(code, template_params)
     sql = FugueSQL(
         code,
         "fugueLanguage",
         ignore_case=self.conf.get_or_throw(FUGUE_SQL_CONF_IGNORE_CASE,
                                            bool),
         simple_assign=self.conf.get_or_throw(FUGUE_SQL_CONF_SIMPLE_ASSIGN,
                                              bool),
     )
     dfs = {
         k: v
         for k, v in params.items() if isinstance(v, WorkflowDataFrame)
     }
     v = _Extensions(sql, FugueSQLHooks(), self, dfs, local_vars=params)
     v.visit(sql.tree)
     return v.variables
Esempio n. 5
0
 def assert_eq(expr, varname, sign):
     sql = FugueSQL(expr,
                    "fugueAssignment",
                    ignore_case=True,
                    simple_assign=True)
     v = _VisitorBase(sql)
     obj = v.visit(sql.tree)
     assert (varname, sign) == obj
Esempio n. 6
0
 def assert_eq(expr, expected):
     sql = FugueSQL(expr, "fugueJsonValue", ignore_case=True)
     v = _VisitorBase(sql)
     obj = v.visit(sql.tree)
     if expected is None:
         assert obj is None
     else:
         assert expected == obj
Esempio n. 7
0
 def assert_eq(expr, is_checkpoint, value):
     sql = FugueSQL(expr,
                    "fuguePersist",
                    ignore_case=True,
                    simple_assign=True)
     v = _VisitorBase(sql)
     obj = v.visit(sql.tree)
     assert (is_checkpoint, value) == obj
Esempio n. 8
0
def assert_eq(expr, expected: FugueWorkflow):
    global_vars, local_vars = get_caller_global_local_vars()
    sql = FugueSQL(expr, "fugueLanguage", ignore_case=True, simple_assign=True)
    wf = FugueWorkflow()
    v = _Extensions(
        sql, FugueSQLHooks(), wf, global_vars=global_vars, local_vars=local_vars
    )
    obj = v.visit(sql.tree)
    assert expected.spec_uuid() == v.workflow.spec_uuid()
Esempio n. 9
0
 def assert_eq(expr, using, params, schema):
     sql = FugueSQL(expr,
                    "fugueSingleOutputExtensionCommon",
                    ignore_case=True)
     v = _VisitorBase(sql)
     obj = v.visit(sql.tree)
     assert using == obj["using"]
     if params is None:
         assert "params" not in obj
     else:
         assert params == obj["params"]
     if schema is None:
         assert "schema" not in obj
     else:
         assert obj["schema"] == schema
Esempio n. 10
0
def bad_syntax(
    *code,
    rule="fugueLanguage",
    ignore_case=True,
    simple_assign=False,
    ansi_sql=False,
    match=None
):
    for c in _enum_comb(*code):
        with raises(FugueSQLSyntaxError, match=match):
            FugueSQL(
                c,
                rule,
                ignore_case=ignore_case,
                simple_assign=simple_assign,
                ansi_sql=ansi_sql,
            )
Esempio n. 11
0
def good_syntax(
    *code,
    rule="fugueLanguage",
    ignore_case=True,
    simple_assign=False,
    ansi_sql=False,
    show=False
):
    for c in _enum_comb(*code):
        s = FugueSQL(
            c,
            rule,
            ignore_case=ignore_case,
            simple_assign=simple_assign,
            ansi_sql=ansi_sql,
        )
        if show:
            _print_tree(s.tree)
Esempio n. 12
0
 def assert_eq(expr, expected):
     sql = FugueSQL(expr, "fuguePrepartition", ignore_case=True)
     v = _VisitorBase(sql)
     obj = json.dumps(v.visit(sql.tree).jsondict)
     assert json.dumps(expected.jsondict) == obj
Esempio n. 13
0
 def assert_eq(expr, expected):
     sql = FugueSQL(expr, "fugueParams", ignore_case=True)
     v = _VisitorBase(sql)
     obj = v.visit(sql.tree)
     assert expected == obj
Esempio n. 14
0
def assert_eq(expr, expected: FugueWorkflow):
    sql = FugueSQL(expr, "fugueLanguage", ignore_case=True, simple_assign=True)
    wf = FugueWorkflow()
    v = _Extensions(sql, FugueSQLHooks(), wf)
    obj = v.visit(sql.tree)
    assert expected.spec_uuid() == v.workflow.spec_uuid()