def denormalize(args): # raise NotImplementedError("Temporarily disabled.") cube_list = args.cube config = read_config(args.config) workspace = cubes.Workspace(config) if not cube_list: cube_list = [cube["name"] for cube in workspace.list_cubes()] view_schema = args.schema # or workspace.options.get("denormalized_view_schema") view_prefix = args.prefix or workspace.options.get("denormalized_view_prefix") for cube_name in cube_list: cube = workspace.cube(cube_name) store = workspace.get_store(cube.store_name or "default") view_name = view_prefix + cube_name if view_prefix else cube_name print("denormalizing cube '%s' into '%s'" % (cube_name, view_name)) store.create_denormalized_view(cube, view_name, materialize=args.materialize, replace=args.replace, create_index=args.index, keys_only=False, schema=view_schema)
def convert_model(args): raise NotImplementedError("Temporarily disabled.") path = args.target workspace = cubes.Workspace() for model in args.models: workspace.import_model(model) if args.format == "bundle": if os.path.exists(path): if not os.path.isdir(path): raise CubesError("Target exists and is a file, " "can not replace") elif not os.path.exists(os.path.join(path, "model.json")): raise CubesError("Target is not a model directory, " "can not replace.") if args.force: shutil.rmtree(path) else: raise CubesError("Target already exists. " "Remove it or use --force.") cubes.write_model_bundle(model, args.target) elif args.format == "json": info = model.to_dict(target="origin") if not path: print(json.dumps(info)) else: with open(path, "w") as f: json.dump(info, f)
def test(aggregate, exclude_stores, include_stores, config, cube): """Test every cube in the model""" workspace = cubes.Workspace(config) errors = [] if cube: cube_list = cube else: cube_list = [c["name"] for c in workspace.list_cubes()] exclude = exclude_stores or [] include = include_stores or [] tested = 0 for name in cube_list: cube = workspace.cube(name) click.echo("testing {}: ".format(name), nl=False) if cube.store_name in exclude \ or (include and cube.store_name not in include): click.echo("pass") continue try: browser = workspace.browser(name) except Exception as e: errors.append((name, e)) click.echo("BROWSER ERROR") continue tested += 1 try: facts = browser.test(aggregate=aggregate) except NotImplementedError: click.echo("pass - no test") except CubesError as e: errors.append((name, e)) click.echo("ERROR") click.echo() click.echo("tested %d cubes" % tested) if errors: click.echo("%d ERRORS:" % len(errors)) for (cube, e) in errors: if hasattr(e, "error_type"): etype = e.error_type else: etype = str(type(e)) click.echo("%s: %s - %s" % (cube, etype, str(e))) else: click.echo("test passed")
def run_test(args): """Test every cube in the model.""" workspace = cubes.Workspace(args.config) errors = [] if args.cube: cube_list = args.cube else: cube_list = [c["name"] for c in workspace.list_cubes()] exclude = args.exclude_stores or [] include = args.include_stores or [] tested = 0 for name in cube_list: cube = workspace.cube(name) sys.stdout.write("testing %s: " % name) if cube.store_name in exclude \ or (include and cube.store_name not in include): sys.stdout.write("pass\n") continue try: browser = workspace.browser(name) except Exception as e: errors.append((name, e)) sys.stdout.write("BROWSER ERROR\n") continue tested += 1 try: facts = browser.test(aggregate=args.aggregate) except NotImplementedError: sys.stdout.write("pass - no test\n") except CubesError as e: errors.append((name, e)) sys.stdout.write("ERROR\n") print("\ntested %d cubes" % tested) if errors: print("%d ERRORS:" % len(errors)) for (cube, e) in errors: if hasattr(e, "error_type"): etype = e.error_type else: etype = str(type(e)) print("%s: %s - %s" % (cube, etype, str(e))) else: print("test passed")
def pre_aggregate(args): """Create pre-aggregated table """ workspace = cubes.Workspace(args.config) cube_list = args.cube if not cube_list: cube_list = [cube["name"] for cube in workspace.list_cubes()] for cube_name in cube_list: cube = workspace.cube(cube_name) store = workspace.get_store(cube.store_name or "default") browser = workspace.browser(cube) store.create_cube_aggregate(browser, replace=args.replace)
def initialize_model(): global model global workspace #model = cubes.load_model(MODEL_PATH) # workspace = cubes.create_workspace("sql",url=DB_URL, # fact_prefix="ft_", # dimension_prefix="dm_") # engine = sqlalchemy.create_engine(DB_URL) # connection = engine.connect() workspace = cubes.Workspace(config='slicer.ini') #workspace.register_default_store("sql",url=DB_URL) print MODEL_PATH print DB_URL
def sql(ctx, store, config): """SQL store commands""" ctx.obj.workspace = cubes.Workspace(config) ctx.obj.store = ctx.obj.workspace.get_store(store)
def test_select_hierarchies(self): ws = cubes.Workspace() dim_time = ws.dimension("base_time") dim_date = ws.dimension("base_date") self.assertLess(len(dim_date.hierarchies), len(dim_time.hierarchies))
def test_base_existence(self): ws = cubes.Workspace() dim = ws.dimension("base_time") self.assertEqual(dim.name, "base_time")
def test_base_ignorance(self): ws = cubes.Workspace(load_base_model=False) with self.assertRaises(NoSuchDimensionError): ws.dimension("base_time")