def test_truncate_fact_table_cli(self): data_marts_api.create_taxon_dimension('taxon_dim') data_marts_api.create_fact_table('fact_table', ['taxon_dim'], ['n']) class TestCLIFactTablePublisher(BaseFactTablePublisher): @classmethod def get_key(cls): return 'test_cli_fact_table_publisher' def _process(self, *args, **kwargs): dim = data_marts_api.get_dimension('taxon_dim') df = dim.get_values() df['n'] = df.index df['taxon_dim_id'] = df.index return df[['taxon_dim_id', 'n']] data_marts_api.populate_fact_table('fact_table', 'test_cli_fact_table_publisher') runner = CliRunner() result = runner.invoke( data_marts.truncate_fact_table_cli, ["fact_table"], ) self.assertEqual(result.exit_code, 0)
def test_get_registered_fact_tables(self): fact_tables = data_marts_api.get_registered_fact_tables() self.assertEqual(len(fact_tables), 0) data_marts_api.create_vector_dimension("ncl_adm1") data_marts_api.create_fact_table( 'fact_table', ['ncl_adm1', ], ['measure_1', ] ) fact_tables = data_marts_api.get_registered_fact_tables() self.assertEqual(len(fact_tables), 1)
def test_create_fact_table(self): data_marts_api.create_vector_dimension("ncl_adm1") data_marts_api.create_fact_table( 'fact_table', ['ncl_adm1', ], ['measure_1', ], ) data_marts_api.get_fact_table('fact_table') self.assertRaises( DimensionNotRegisteredError, data_marts_api.create_fact_table, 'fact_table_2', ['ncl', ], ['measure_2', ], )
def test_truncate_fact_table(self): dim_1 = TestDimension("dim_1") dim_2 = TestDimension("dim_2") dim_1.create_dimension() dim_2.create_dimension() dim_1.populate_from_publisher() dim_2.populate_from_publisher() data_marts_api.create_fact_table( "test_fact", dimension_names=['dim_1', 'dim_2'], measure_names=['measure_1'], ) data_marts_api.populate_fact_table( 'test_fact', TestFactTablePublisher.get_key() ) data_marts_api.truncate_fact_table('test_fact')
def create_fact_table_cli(name, dimension, measure): """ Create and register a fact table from existing dimensions. Use -d <dimension_name> for each dimension, and -m <measure_name> for each measure. """ from niamoto.api import data_marts_api click.echo( "Creating the '{}' fact table...".format(name) ) data_marts_api.create_fact_table( name, dimension_names=dimension, measure_names=measure ) click.echo( "The '{}' fact table had been successfully created!".format(name) )
def test_get_dimensional_model(self): dim_1 = TestDimension("dim_1") dim_2 = TestDimension("dim_2") dim_1.create_dimension() dim_2.create_dimension() data_marts_api.create_fact_table( "test_fact", dimension_names=['dim_1', 'dim_2'], measure_names=['measure_1'], ) dm = data_marts_api.get_dimensional_model( 'test_fact', [ { "name": "measure_1_sum", "function": "sum", "measure": "measure_1", }, ] ) self.assertIsInstance(dm, DimensionalModel) wk = dm.get_cubes_workspace()