Esempio n. 1
0
def exec_command(
    compile_only: bool = False,
    yes: bool = False,
):
    compiled_transforms: List[Tuple[CompiledTransform, Path]] = []

    transforms_with_path = get_transforms()

    if len(transforms_with_path) == 0:
        echo_info('No transforms found...')
        return

    transform_compiler = TransformCompiler(get_company_id())

    file_writer = FileWriter()

    echo_info('Compiling transforms...')
    with tqdm(transforms_with_path) as compiling_bar:
        for transform, transform_path in compiling_bar:
            try:
                compiled_transform = transform_compiler.compile(
                    transform=transform)
                compiled_transforms.append(
                    (compiled_transform, transform_path))

                compiled_sql_path = file_writer.write_compiled_transform(
                    compiled_transform)

                compiling_bar.write(
                    f'[{transform.name}] writing compiled query to {compiled_sql_path}'
                )
            except Exception as e:
                compiling_bar.write(
                    f'\nError: Failed to compile transform {transform_path}:\n  {str(e)}'
                )

    if len(compiled_transforms) == 0:
        echo_info('No transforms to execute...')
        return

    if compile_only or not yes and not click.confirm(
            'Do you want to execute transforms?'):
        return

    echo_info('Executing transforms...')
    with tqdm(compiled_transforms) as exec_bar:
        for (compiled_transform, transform_path) in exec_bar:
            try:
                exec_bar.write(
                    f'Executing: {compiled_transform.transform.name} on {compiled_transform.transform.connection_name}'
                )

                TransformExecutor.execute(compiled_transform)
                exec_bar.write(
                    f'\u2713 [{compiled_transform.transform.connection_name}] {transform.name}'
                )
            except Exception as e:
                exec_bar.write(
                    f'\u2717 [{compiled_transform.transform.connection_name}] {transform.name} \nError: Failed to execute transform {transform_path}:\n  {str(e)}'
                )
Esempio n. 2
0
    def to_husky(origin: PanoField) -> Taxon:
        """Maps external field definitions to internal taxon representation"""

        slug = origin.slug if origin.data_source is None else f'{origin.data_source}{NAMESPACE_DELIMITER}{origin.slug}'
        aggregation = None
        if origin.aggregation:
            aggregation = AggregationDefinition.parse_obj(
                origin.aggregation.to_dict())

        validation = EnumHelper.from_value(ValidationType, origin.data_type)
        assert validation

        return Taxon(
            slug=slug,
            taxon_group=origin.group,
            display_name=origin.display_name,
            taxon_type=origin.field_type,
            validation_type=validation,
            taxon_description=origin.description,
            data_source=origin.data_source,
            calculation=origin.calculation,
            aggregation=aggregation,
            display_state=DisplayState.visible,
            company_id=get_company_id(),
        )
Esempio n. 3
0
    def to_husky(origin: PanoModel) -> HuskyModel:
        """Maps external panoramic model to internal husky model"""
        assert origin.virtual_data_source

        fdq_model = FdqModel.parse_obj({
            **origin.to_dict(), 'visibility':
            ModelVisibility.available
        })
        husky_model = FdqModelMapper.to_internal(fdq_model,
                                                 origin.virtual_data_source,
                                                 get_company_id())

        return husky_model
Esempio n. 4
0
def cmd():
    from panoramic.cli.husky.core.virtual_state.mappers import VirtualStateMapper
    from panoramic.cli.local import get_state

    state = get_state()
    internal_state = VirtualStateMapper.to_husky(state)
    print(internal_state.virtual_data_sources)

    from panoramic.cli.config.companies import get_company_id
    from panoramic.cli.husky.core.taxonomy.getters import Taxonomy

    Taxonomy.preload_taxons_from_state()
    Taxonomy.precalculate_tel_metadata()

    taxons = Taxonomy.get_taxons(get_company_id())
    print(taxons)