Exemple #1
0
    def __init__(self, config=None, datasources=None, ds_priority=None):
        self.id = None
        self.name = None
        self.meta = None
        self._datasources = OrderedDict()
        self._metrics = {}
        self._dimensions = {}
        self._supported_dimension_cache = {}

        for ds in datasources or []:
            self.add_datasource(ds, skip_integrity_checks=True)

        if config:
            config = load_warehouse_config(config)
            self.apply_config(config, skip_integrity_checks=True)

        raiseifnot(self._datasources,
                   "No datasources provided or found in config")

        self._add_default_display_names()
        self.run_integrity_checks()

        self.ds_priority = ds_priority or list(self._datasources.keys())

        raiseifnot(
            isinstance(self.ds_priority, list),
            ("Invalid format for ds_priority, must be list of datasource names: %s"
             % self.ds_priority),
        )
        raiseifnot(
            len(self.ds_priority) == len(self._datasources),
            "Length mismatch between ds_priority and datasources",
        )
        for ds_name in self.ds_priority:
            raiseifnot(
                ds_name in self._datasources,
                "Datasource %s is in ds_priority but not in datasource map" %
                ds_name,
            )
Exemple #2
0
from zillion.configs import load_warehouse_config
from zillion.core import RollupTypes, info
from zillion.warehouse import Warehouse

config = load_warehouse_config("../examples/example_wh_config.json")


def test_example_wh_init():
    wh = Warehouse(config=config)
    wh.print_info()


def test_example_wh_report1():
    wh = Warehouse(config=config)
    result = wh.execute(metrics=["sales", "leads", "revenue"],
                        dimensions=["partner_name"])
    assert result
    info(result.df)


def test_example_wh_report2():
    wh = Warehouse(config=config)
    result = wh.execute(
        metrics=["sales", "leads", "revenue"],
        dimensions=["campaign_name"],
        criteria=[("partner_name", "=", "Partner A")],
    )
    assert result
    info(result.df)

Exemple #3
0
)
from zillion.core import *
from zillion.datasource import (
    DataSource,
    AdHocDataTable,
    SQLiteDataTable,
    get_adhoc_datasource_filename,
    get_adhoc_datasource_url,
)
from zillion.field import DATETIME_CONVERSION_FIELDS
from zillion.model import *
from zillion.report import Report
from zillion.warehouse import Warehouse

DEFAULT_TEST_DB = "testdb1"
TEST_WH_CONFIG = load_warehouse_config("test_wh_config.json")
TEST_ADHOC_CONFIG = load_warehouse_config("test_adhoc_ds_config.json")
REMOTE_CONFIG_URL = "https://raw.githubusercontent.com/totalhack/zillion/master/tests/test_wh_config.json"
test_config = zillion_config["TEST"]

logging.getLogger().setLevel(logging.INFO)


@contextmanager
def update_zillion_config(updates):
    """Helper to make temporary updates to global config"""
    old = {k: v for k, v in zillion_config.items() if k in updates}
    try:
        zillion_config.update(updates)
        yield
    finally:
Exemple #4
0
def test_load_remote_wh_config():
    cfg = load_warehouse_config(REMOTE_CONFIG_URL)