How to use the spectacles.lookml.Dimension function in spectacles

To help you get started, we’ve selected a few spectacles examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github spectacles-ci / spectacles / tests / test_lookml.py View on Github external
def test_dimension_from_json():
    model_name = "eye_exam"
    explore_name = "users"
    json_dict = load_resource("response_dimensions.json")
    dimension = Dimension.from_json(json_dict[0], model_name, explore_name)
    assert dimension.name == "test_view.dimension_one"
    assert dimension.model_name == model_name
    assert dimension.explore_name == explore_name
    assert dimension.type == "number"
    assert dimension.url == "/projects/spectacles/files/test_view.view.lkml?line=340"
    assert dimension.sql == "${TABLE}.dimension_one "
    assert not dimension.ignore
github spectacles-ci / spectacles / tests / test_lookml.py View on Github external
def test_ignored_dimension_with_no_whitespace():
    name = "test_view.dimension_one"
    model_name = "eye_exam"
    explore_name = "users"
    dimension_type = "number"
    url = "/projects/spectacles/files/test_view.view.lkml?line=340"
    sql = "--spectacles:ignore\n${TABLE}.dimension_one "
    dimension = Dimension(name, model_name, explore_name, dimension_type, sql, url)
    assert dimension.ignore
github spectacles-ci / spectacles / tests / test_lookml.py View on Github external
def test_ignored_dimension_with_whitespace():
    name = "test_view.dimension_one"
    model_name = "eye_exam"
    explore_name = "users"
    dimension_type = "number"
    url = "/projects/spectacles/files/test_view.view.lkml?line=340"
    sql = " -- spectacles: ignore\n${TABLE}.dimension_one "
    dimension = Dimension(name, model_name, explore_name, dimension_type, sql, url)
    assert dimension.ignore
github spectacles-ci / spectacles / spectacles / lookml.py View on Github external
def __eq__(self, other):
        if not isinstance(other, Dimension):
            return NotImplemented

        return (
            self.name == other.name
            and self.model_name == other.model_name
            and self.explore_name == other.explore_name
            and self.type == other.type
            and self.url == other.url
        )
github spectacles-ci / spectacles / spectacles / validators / validator.py View on Github external
)

        for model in project_models:
            model.explores = [
                explore
                for explore in model.explores
                if is_selected(model.name, explore.name, selectors, exclusions)
            ]

            if build_dimensions:
                for explore in model.explores:
                    dimensions_json = self.client.get_lookml_dimensions(
                        model.name, explore.name
                    )
                    for dimension_json in dimensions_json:
                        dimension = Dimension.from_json(
                            dimension_json, model.name, explore.name
                        )
                        dimension.url = self.client.base_url + dimension.url
                        if not dimension.ignore:
                            explore.add_dimension(dimension)

        self.project.models = [
            model for model in project_models if len(model.explores) > 0
        ]
github spectacles-ci / spectacles / spectacles / validators / sql.py View on Github external
def _handle_query_result(self, result: QueryResult) -> Optional[SqlError]:
        query = self.get_query_by_task_id(result.query_task_id)
        if result.status in ("complete", "error"):
            self._running_queries.remove(query)
            self.query_slots += 1
            lookml_object = query.lookml_ref
            lookml_object.queried = True

            if result.status == "error" and result.error:
                model_name = lookml_object.model_name
                dimension_name: Optional[str] = None
                if isinstance(lookml_object, Dimension):
                    explore_name = lookml_object.explore_name
                    dimension_name = lookml_object.name
                else:
                    explore_name = lookml_object.name

                sql_error = SqlError(
                    model=model_name,
                    explore=explore_name,
                    dimension=dimension_name,
                    explore_url=query.explore_url,
                    lookml_url=getattr(lookml_object, "url", None),
                    **result.error,
                )
                lookml_object.errors.append(sql_error)
                return sql_error
        return None