mongo_data_source.py 964 B

123456789101112131415161718192021222324252627282930
  1. # -*- coding:utf-8 -*-
  2. from dw_base.datax.datasources.data_source import DataSource
  3. # Mongo DataSource
  4. DS_TYPE_MONGO = 'mongo'
  5. DS_MONGO_KEYS = ['address']
  6. class MongoDataSource(DataSource):
  7. def __init__(self, ds_file: str):
  8. super(MongoDataSource, self).__init__(ds_file)
  9. self.source_type = DS_TYPE_MONGO
  10. self.keys = DS_MONGO_KEYS
  11. def get_datasource_dict(self):
  12. for key in self.keys:
  13. try:
  14. value = self.config_parser.get('base', key)
  15. except KeyError:
  16. raise KeyError('%s must specified at %s data source config.' % (key, self.source_type))
  17. if value:
  18. if key == 'address':
  19. self.ds_dict[key] = [value]
  20. else:
  21. self.ds_dict[key] = value
  22. else:
  23. raise KeyError('%s must specified at %s data source config.' % (key, self.source_type))
  24. return self.ds_dict