Example #1
0
def test_str_tupleset_fail_unstable(param):
    with pytest.raises(
            TypeError,
            match="which has type {} has an unstable iteration order".format(
                type(param).__name__),
    ):
        converter_str_tupleset(param)
def _process_dimension_columns(dimension_columns, cube):
    """
    Process and check given dimension columns.

    Parameters
    ----------
    dimension_columns: Optional[Iterable[str]]
        Dimension columns of the query, may result in projection.
    cube: Cube
        Cube specification.

    Returns
    -------
    dimension_columns: Tuple[str, ...]
        Real dimension columns.
    """
    if dimension_columns is None:
        return cube.dimension_columns
    else:
        dimension_columns = converter_str_tupleset(dimension_columns)
        missing = set(dimension_columns) - set(cube.dimension_columns)
        if missing:
            raise ValueError(
                "Following dimension columns were requested but are missing from the cube: {missing}".format(
                    missing=", ".join(sorted(missing))
                )
            )
        if len(dimension_columns) == 0:
            raise ValueError("Dimension columns cannot be empty.")
        return dimension_columns
def _process_partition_by(partition_by, cube, all_available_columns, indexed_columns):
    """
    Process and check given partition-by columns.

    Parameters
    ----------
    partition_by: Optional[Iterable[str]]
        By which column logical partitions should be formed.
    cube: Cube
        Cube specification.
    all_available_columns: Set[str]
        All columns that are available for query.
    indexed_columns: Dict[str, Set[str]]
        Indexed columns per ktk_cube dataset ID.

    Returns
    -------
    partition_by: Tuple[str, ...]
        Real partition-by columns, may be empty.
    """
    if partition_by is None:
        return []
    else:
        partition_by = converter_str_tupleset(partition_by)
        partition_by_set = set(partition_by)

        missing_available = partition_by_set - all_available_columns
        if missing_available:
            raise ValueError(
                "Following partition-by columns were requested but are missing from the cube: {missing}".format(
                    missing=", ".join(sorted(missing_available))
                )
            )

        missing_indexed = partition_by_set - reduce(
            set.union, indexed_columns.values(), set()
        )
        if missing_indexed:
            raise ValueError(
                "Following partition-by columns are not indexed and cannot be used: {missing}".format(
                    missing=", ".join(sorted(missing_indexed))
                )
            )

        return partition_by
Example #4
0
def test_str_tupleset_fail_duplicates():
    with pytest.raises(ValueError,
                       match="Tuple-set contains duplicates: foo, foo"):
        converter_str_tupleset([b"foo", "foo"])
Example #5
0
def test_str_tupleset_ok(param, expected):
    actual = converter_str_tupleset(param)
    assert isinstance(actual, tuple)
    assert actual == expected
    assert all(isinstance(x, str) for x in actual)