def test_conversion(self): # type: () -> None transformer = DictToModel() config = ConfigFactory.from_dict({ MODEL_CLASS: 'databuilder.models.dashboard.dashboard_execution.DashboardExecution', }) transformer.init(conf=config) actual = transformer.transform({ 'dashboard_group_id': 'foo', 'dashboard_id': 'bar', 'execution_timestamp': 123456789, 'execution_state': 'succeed', 'product': 'mode', 'cluster': 'gold' }) self.assertTrue(isinstance(actual, DashboardExecution)) self.assertEqual( actual.__repr__(), DashboardExecution(dashboard_group_id='foo', dashboard_id='bar', execution_timestamp=123456789, execution_state='succeed', product='mode', cluster='gold').__repr__())
def init(self, conf: ConfigTree) -> None: self._conf = conf self.query = """query { workbooks { id name projectName updatedAt } }""" self._extractor = self._build_extractor() transformers: List[Transformer] = [] timestamp_str_to_epoch_transformer = TimestampStringToEpoch() timestamp_str_to_epoch_transformer.init(conf=Scoped.get_scoped_conf( self._conf, timestamp_str_to_epoch_transformer.get_scope()).with_fallback( ConfigFactory.from_dict({ FIELD_NAME: 'last_modified_timestamp', }))) transformers.append(timestamp_str_to_epoch_transformer) dict_to_model_transformer = DictToModel() dict_to_model_transformer.init(conf=Scoped.get_scoped_conf( self._conf, dict_to_model_transformer.get_scope() ).with_fallback( ConfigFactory.from_dict({ MODEL_CLASS: 'databuilder.models.dashboard.dashboard_last_modified.DashboardLastModifiedTimestamp' }))) transformers.append(dict_to_model_transformer) self._transformer = ChainedTransformer(transformers=transformers)
def init(self, conf: ConfigTree) -> None: self._conf = conf self.query = """query externalTables($externalTableTypes: [String]) { databases (filter: {connectionTypeWithin: $externalTableTypes}) { name connectionType description tables { name } } }""" self.query_variables = { 'externalTableTypes': self._conf.get_list( TableauDashboardExternalTableExtractor.EXTERNAL_TABLE_TYPES) } self._extractor = self._build_extractor() transformers = [] dict_to_model_transformer = DictToModel() dict_to_model_transformer.init(conf=Scoped.get_scoped_conf( self._conf, dict_to_model_transformer.get_scope()).with_fallback( ConfigFactory.from_dict({ MODEL_CLASS: 'databuilder.models.table_metadata.TableMetadata' }))) transformers.append(dict_to_model_transformer) self._transformer = ChainedTransformer(transformers=transformers)
def init(self, conf: ConfigTree) -> None: self._conf = conf self.query = """query { workbooks { name projectName upstreamTables { name schema database { name connectionType } } } }""" self._extractor = self._build_extractor() transformers = [] dict_to_model_transformer = DictToModel() dict_to_model_transformer.init( conf=Scoped.get_scoped_conf(self._conf, dict_to_model_transformer.get_scope()).with_fallback( ConfigFactory.from_dict( {MODEL_CLASS: 'databuilder.models.dashboard.dashboard_table.DashboardTable'}))) transformers.append(dict_to_model_transformer) self._transformer = ChainedTransformer(transformers=transformers)
def init(self, conf: ConfigTree) -> None: self._conf = conf restapi_query = self._build_restapi_query() self._extractor = ModeDashboardUtils.create_mode_rest_api_extractor( restapi_query=restapi_query, conf=self._conf) # Payload from RestApiQuery has timestamp which is ISO8601. Here we are using TimestampStringToEpoch to # transform into epoch and then using DictToModel to convert Dictionary to Model transformers: List[Transformer] = [] timestamp_str_to_epoch_transformer = TimestampStringToEpoch() timestamp_str_to_epoch_transformer.init(conf=Scoped.get_scoped_conf( self._conf, timestamp_str_to_epoch_transformer.get_scope()).with_fallback( ConfigFactory.from_dict({ FIELD_NAME: 'execution_timestamp', }))) transformers.append(timestamp_str_to_epoch_transformer) dict_to_model_transformer = DictToModel() dict_to_model_transformer.init(conf=Scoped.get_scoped_conf( self._conf, dict_to_model_transformer.get_scope() ).with_fallback( ConfigFactory.from_dict({ MODEL_CLASS: 'databuilder.models.dashboard.dashboard_execution.DashboardExecution' }))) transformers.append(dict_to_model_transformer) self._transformer = ChainedTransformer(transformers=transformers)
def init(self, conf: ConfigTree) -> None: self._conf = conf restapi_query = self._build_restapi_query() self._extractor = ModeDashboardUtils.create_mode_rest_api_extractor( restapi_query=restapi_query, conf=self._conf) # Remove all unnecessary fields because User model accepts all attributes and push it to Neo4j. transformers: List[Transformer] = [] remove_fields_transformer = RemoveFieldTransformer() remove_fields_transformer.init(conf=Scoped.get_scoped_conf( self._conf, remove_fields_transformer.get_scope()).with_fallback( ConfigFactory.from_dict({ FIELD_NAMES: ['organization', 'mode_user_resource_path', 'product'] }))) transformers.append(remove_fields_transformer) dict_to_model_transformer = DictToModel() dict_to_model_transformer.init(conf=Scoped.get_scoped_conf( self._conf, dict_to_model_transformer.get_scope()).with_fallback( ConfigFactory.from_dict( {MODEL_CLASS: 'databuilder.models.user.User'}))) transformers.append(dict_to_model_transformer) self._transformer = ChainedTransformer(transformers=transformers)
def init(self, conf): # type: (ConfigTree) -> None self._conf = conf restapi_query = self._build_restapi_query() self._extractor = ModeDashboardUtils.create_mode_rest_api_extractor( restapi_query=restapi_query, conf=self._conf) # Constructing URL using resource path via TemplateVariableSubstitutionTransformer transformers = [] chart_url_transformer = TemplateVariableSubstitutionTransformer() chart_url_transformer.init(conf=Scoped.get_scoped_conf( self._conf, chart_url_transformer.get_scope()).with_fallback( ConfigFactory.from_dict( { FIELD_NAME: 'chart_url', TEMPLATE: 'https://app.mode.com{chart_url}' }))) transformers.append(chart_url_transformer) dict_to_model_transformer = DictToModel() dict_to_model_transformer.init(conf=Scoped.get_scoped_conf( self._conf, dict_to_model_transformer.get_scope() ).with_fallback( ConfigFactory.from_dict({ MODEL_CLASS: 'databuilder.models.dashboard.dashboard_chart.DashboardChart' }))) transformers.append(dict_to_model_transformer) self._transformer = ChainedTransformer(transformers=transformers)
def init(self, conf: ConfigTree) -> None: self._conf = conf self.query = """query { customSQLTables { id name query downstreamWorkbooks { name projectName } } }""" self._extractor = self._build_extractor() transformers = [] dict_to_model_transformer = DictToModel() dict_to_model_transformer.init(conf=Scoped.get_scoped_conf( self._conf, dict_to_model_transformer.get_scope() ).with_fallback( ConfigFactory.from_dict({ MODEL_CLASS: 'databuilder.models.dashboard.dashboard_query.DashboardQuery' }))) transformers.append(dict_to_model_transformer) self._transformer = ChainedTransformer(transformers=transformers)
def init(self, conf: ConfigTree) -> None: self._conf = conf self.dashboard_group_ids_to_skip = self._conf.get_list( DASHBOARD_GROUP_IDS_TO_SKIP, []) restapi_query = self._build_restapi_query() self._extractor = ModeDashboardUtils.create_mode_rest_api_extractor( restapi_query=restapi_query, conf=self._conf) # Payload from RestApiQuery has timestamp which is ISO8601. Here we are using TimestampStringToEpoch to # transform into epoch and then using DictToModel to convert Dictionary to Model transformers: List[Transformer] = [] timestamp_str_to_epoch_transformer = TimestampStringToEpoch() timestamp_str_to_epoch_transformer.init(conf=Scoped.get_scoped_conf( self._conf, timestamp_str_to_epoch_transformer.get_scope()).with_fallback( ConfigFactory.from_dict({ FIELD_NAME: 'created_timestamp', }))) transformers.append(timestamp_str_to_epoch_transformer) dashboard_group_url_transformer = TemplateVariableSubstitutionTransformer( ) dashboard_group_url_transformer.init(conf=Scoped.get_scoped_conf( self._conf, dashboard_group_url_transformer.get_scope() ).with_fallback( ConfigFactory.from_dict({ VAR_FIELD_NAME: 'dashboard_group_url', TEMPLATE: 'https://app.mode.com/{organization}/spaces/{dashboard_group_id}' }))) transformers.append(dashboard_group_url_transformer) dashboard_url_transformer = TemplateVariableSubstitutionTransformer() dashboard_url_transformer.init(conf=Scoped.get_scoped_conf( self._conf, dashboard_url_transformer.get_scope() ).with_fallback( ConfigFactory.from_dict({ VAR_FIELD_NAME: 'dashboard_url', TEMPLATE: 'https://app.mode.com/{organization}/reports/{dashboard_id}' }))) transformers.append(dashboard_url_transformer) dict_to_model_transformer = DictToModel() dict_to_model_transformer.init(conf=Scoped.get_scoped_conf( self._conf, dict_to_model_transformer.get_scope() ).with_fallback( ConfigFactory.from_dict({ MODEL_CLASS: 'databuilder.models.dashboard.dashboard_metadata.DashboardMetadata' }))) transformers.append(dict_to_model_transformer) self._transformer = ChainedTransformer(transformers=transformers)
def init(self, conf: ConfigTree) -> None: self._conf = conf restapi_query = self._build_restapi_query() self._extractor = ModeDashboardUtils.create_mode_rest_api_extractor( restapi_query=restapi_query, conf=self._conf ) dict_to_model_transformer = DictToModel() dict_to_model_transformer.init( conf=Scoped.get_scoped_conf(self._conf, dict_to_model_transformer.get_scope()).with_fallback( ConfigFactory.from_dict( {MODEL_CLASS: 'databuilder.models.dashboard.dashboard_chart.DashboardChart'}))) self._transformer = dict_to_model_transformer
def init(self, conf): # type: (ConfigTree) -> None self._conf = conf restapi_query = self._build_restapi_query() self._extractor = ModeDashboardUtils.create_mode_rest_api_extractor( restapi_query=restapi_query, conf=self._conf) # Constructing URL using several ID via TemplateVariableSubstitutionTransformer transformers = [] variable_substitution_transformer = TemplateVariableSubstitutionTransformer( ) variable_substitution_transformer.init(conf=Scoped.get_scoped_conf( self._conf, variable_substitution_transformer.get_scope()).with_fallback( ConfigFactory.from_dict({ FIELD_NAME: 'url', TEMPLATE: 'https://app.mode.com/{organization}' '/reports/{dashboard_id}/queries/{query_id}' }))) transformers.append(variable_substitution_transformer) # Escape backslash as it breaks Cypher statement. replace_transformer = RegexStrReplaceTransformer() replace_transformer.init(conf=Scoped.get_scoped_conf( self._conf, replace_transformer.get_scope()).with_fallback( ConfigFactory.from_dict({ REGEX_REPLACE_TUPLE_LIST: [('\\', '\\\\')], ATTRIBUTE_NAME: 'query_text' }))) transformers.append(replace_transformer) dict_to_model_transformer = DictToModel() dict_to_model_transformer.init(conf=Scoped.get_scoped_conf( self._conf, dict_to_model_transformer.get_scope() ).with_fallback( ConfigFactory.from_dict({ MODEL_CLASS: 'databuilder.models.dashboard.dashboard_query.DashboardQuery' }))) transformers.append(dict_to_model_transformer) self._transformer = ChainedTransformer(transformers=transformers)