コード例 #1
0
ファイル: sql.py プロジェクト: xyuan/mensor
    def __init__(self, *args, sql=None, executor=None, **kwargs):

        if not executor:
            executor = DebugSQLExecutor()
        elif isinstance(executor, str):
            executor = SQLExecutor.for_kind(executor)()
        elif issubclass(executor, SQLExecutor):
            executor = executor()

        MeasureProvider.__init__(self, *args, **kwargs)
        self._base_sql = textwrap.dedent(sql).strip() if sql else None
        self.executor = executor
        self.dialect = DIALECTS[executor.dialect]

        self.provides_measure('count',
                              shared=True,
                              distribution=None,
                              default=0)

        self._template_environment = jinja2.Environment(
            loader=jinja2.FunctionLoader(lambda x: x),
            undefined=jinja2.StrictUndefined)
        self._template_environment.filters.update({
            'col': self._col,
            'val': self._val
        })
コード例 #2
0
    def __init__(self, name, data=None, data_transform=None, **kwargs):
        MeasureProvider.__init__(self, name, **kwargs)
        if isinstance(data, str):
            data = pd.read_csv(data)
        self._data = data
        self._data_transform = data_transform

        self.provides_measure('count', shared=True, distribution=None)
コード例 #3
0
    def __init__(self,
                 *args,
                 sql=None,
                 db_client=None,
                 dialect='presto',
                 **kwargs):
        assert db_client is not None, "Must specify an (Omniduct-compatible) database client."

        MeasureProvider.__init__(self, *args, **kwargs)
        self._base_sql = textwrap.dedent(sql).strip() if sql else None
        self.db_client = db_client
        self.dialect = DIALECTS[dialect]

        self.provides_measure('count', shared=True, distribution=None)

        self._template_environment = jinja2.Environment(
            loader=jinja2.FunctionLoader(lambda x: x))
        self._template_environment.filters.update({
            'col': self._col,
            'val': self._val
        })
コード例 #4
0
    def test_strategy_methods(self):
        c = Constraint.from_spec({'*/unit/a': 1, '*/b': 2, 'c': 3})

        self.assertEqual(c.scoped_for_unit_type('unit'),
                         Constraint.from_spec({
                             'a': 1,
                             'c': 3
                         }))
        self.assertEqual(c.scoped_for_unit_type('other'),
                         Constraint.from_spec({'c': 3}))

        mp = MeasureProvider().provides_dimension('b')
        self.assertEqual(c.generic_for_provider(mp),
                         Constraint.from_spec({'b': 2}))