コード例 #1
0
def test_copy_validates():
    cube1 = Cube(dimension_columns=["x"], partition_columns=["p"], uuid_prefix="cube1")
    with pytest.raises(ValueError) as exc:
        cube1.copy(uuid_prefix="cube2++")
    assert (
        str(exc.value) == 'uuid_prefix ("cube2++") must not contain UUID separator ++'
    )
コード例 #2
0
def ensure_valid_cube_indices(existing_datasets: Mapping[str,
                                                         DatasetMetadataBase],
                              cube: Cube) -> Cube:
    """
    Parse all existing datasets and infer the required set of indices. We do not
    allow indices to be removed or added in update steps at the momenent and
    need to make sure that existing ones are updated properly.
    The returned `Cube` instance will be a copy of the input with
    `index_columns` and `suppress_index_on` fields adjusted to reflect the
    existing datasets.
    """
    dataset_indices = []
    for ds in existing_datasets.values():
        for internal_table in ds.table_meta:
            dataset_columns = set(ds.table_meta[internal_table].names)
            table_indices = cube.index_columns & dataset_columns
            compatible_indices = _ensure_compatible_indices(ds, table_indices)
            if compatible_indices:
                dataset_indices.append(set(compatible_indices))
    required_indices = cube.index_columns.union(*dataset_indices)
    suppress_index_on = cube.suppress_index_on.difference(*dataset_indices)
    # Need to remove dimension columns since they *are* technically indices but
    # the cube interface class declares them as not indexed just to add them
    # later on, assuming it is not blacklisted
    return cube.copy(
        index_columns=required_indices - set(cube.dimension_columns),
        suppress_index_on=suppress_index_on,
    )
コード例 #3
0
def test_copy_simple():
    cube1 = Cube(dimension_columns=["x"],
                 partition_columns=["p"],
                 uuid_prefix="cube1")
    cube2 = cube1.copy(uuid_prefix="cube2")
    assert cube1.uuid_prefix == "cube1"
    assert cube2.uuid_prefix == "cube2"
コード例 #4
0
def test_keep_other(driver, function_store):
    df = pd.DataFrame({
        "x": [0, 1, 2, 3],
        "p": [0, 0, 1, 1],
        "v": [10, 11, 12, 13]
    })
    cube1 = Cube(dimension_columns=["x"],
                 partition_columns=["p"],
                 uuid_prefix="cube1")
    cube2 = cube1.copy(uuid_prefix="cube2")

    build_cube(data=df, cube=cube1, store=function_store)
    keys = set(function_store().keys())

    build_cube(data=df, cube=cube2, store=function_store)

    driver(cube=cube2, store=function_store)

    assert set(function_store().keys()) == keys
コード例 #5
0
def test_copy_converts():
    cube1 = Cube(dimension_columns=["x"], partition_columns=["p"], uuid_prefix="cube1")
    cube2 = cube1.copy(dimension_columns="foo")
    assert cube2.dimension_columns == ("foo",)