本文整理汇总了Python中singer.metadata.get方法的典型用法代码示例。如果您正苦于以下问题:Python metadata.get方法的具体用法?Python metadata.get怎么用?Python metadata.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类singer.metadata
的用法示例。
在下文中一共展示了metadata.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _build_query_string
# 需要导入模块: from singer import metadata [as 别名]
# 或者: from singer.metadata import get [as 别名]
def _build_query_string(self, catalog_entry, start_date, end_date=None, order_by_clause=True):
selected_properties = self._get_selected_properties(catalog_entry)
query = "SELECT {} FROM {}".format(",".join(selected_properties), catalog_entry['stream'])
catalog_metadata = metadata.to_map(catalog_entry['metadata'])
replication_key = catalog_metadata.get((), {}).get('replication-key')
if replication_key:
where_clause = " WHERE {} >= {} ".format(
replication_key,
start_date)
if end_date:
end_date_clause = " AND {} < {}".format(replication_key, end_date)
else:
end_date_clause = ""
order_by = " ORDER BY {} ASC".format(replication_key)
if order_by_clause:
return query + where_clause + end_date_clause + order_by
return query + where_clause + end_date_clause
else:
return query
示例2: sync_campaigns
# 需要导入模块: from singer import metadata [as 别名]
# 或者: from singer.metadata import get [as 别名]
def sync_campaigns(STATE, ctx):
catalog = ctx.get_catalog_from_id(singer.get_currently_syncing(STATE))
mdata = metadata.to_map(catalog.get('metadata'))
schema = load_schema("campaigns")
singer.write_schema("campaigns", schema, ["id"], catalog.get('stream_alias'))
LOGGER.info("sync_campaigns(NO bookmarks)")
url = get_url("campaigns_all")
params = {'limit': 500}
with Transformer(UNIX_MILLISECONDS_INTEGER_DATETIME_PARSING) as bumble_bee:
for row in gen_request(STATE, 'campaigns', url, params, "campaigns", "hasMore", ["offset"], ["offset"]):
record = request(get_url("campaigns_detail", campaign_id=row['id'])).json()
record = bumble_bee.transform(lift_properties_and_versions(record), schema, mdata)
singer.write_record("campaigns", record, catalog.get('stream_alias'), time_extracted=utils.now())
return STATE
示例3: do_sync
# 需要导入模块: from singer import metadata [as 别名]
# 或者: from singer.metadata import get [as 别名]
def do_sync(config, catalog, state):
LOGGER.info('Starting sync.')
for stream in catalog['streams']:
stream_name = stream['tap_stream_id']
mdata = metadata.to_map(stream['metadata'])
table_spec = next(s for s in config['tables'] if s['table_name'] == stream_name)
if not stream_is_selected(mdata):
LOGGER.info("%s: Skipping - not selected", stream_name)
continue
singer.write_state(state)
key_properties = metadata.get(mdata, (), 'table-key-properties')
singer.write_schema(stream_name, stream['schema'], key_properties)
LOGGER.info("%s: Starting sync", stream_name)
counter_value = sync_stream(config, state, table_spec, stream)
LOGGER.info("%s: Completed sync (%s rows)", stream_name, counter_value)
LOGGER.info('Done syncing.')
示例4: validate_table_config
# 需要导入模块: from singer import metadata [as 别名]
# 或者: from singer.metadata import get [as 别名]
def validate_table_config(config):
# Parse the incoming tables config as JSON
tables_config = json.loads(config['tables'])
for table_config in tables_config:
if ('search_prefix' in table_config) and (table_config.get('search_prefix') is None):
table_config.pop('search_prefix')
if table_config.get('key_properties') == "" or table_config.get('key_properties') is None:
table_config['key_properties'] = []
elif table_config.get('key_properties') and isinstance(table_config['key_properties'], str):
table_config['key_properties'] = [s.strip() for s in table_config['key_properties'].split(',')]
if table_config.get('date_overrides') == "" or table_config.get('date_overrides') is None:
table_config['date_overrides'] = []
elif table_config.get('date_overrides') and isinstance(table_config['date_overrides'], str):
table_config['date_overrides'] = [s.strip() for s in table_config['date_overrides'].split(',')]
# Reassign the config tables to the validated object
return CONFIG_CONTRACT(tables_config)
示例5: stream_is_selected
# 需要导入模块: from singer import metadata [as 别名]
# 或者: from singer.metadata import get [as 别名]
def stream_is_selected(mdata):
return mdata.get((), {}).get('selected', False)
示例6: build_state
# 需要导入模块: from singer import metadata [as 别名]
# 或者: from singer.metadata import get [as 别名]
def build_state(raw_state, catalog):
state = {}
for catalog_entry in catalog['streams']:
tap_stream_id = catalog_entry['tap_stream_id']
catalog_metadata = metadata.to_map(catalog_entry['metadata'])
replication_method = catalog_metadata.get((), {}).get('replication-method')
version = singer.get_bookmark(raw_state,
tap_stream_id,
'version')
# Preserve state that deals with resuming an incomplete bulk job
if singer.get_bookmark(raw_state, tap_stream_id, 'JobID'):
job_id = singer.get_bookmark(raw_state, tap_stream_id, 'JobID')
batches = singer.get_bookmark(raw_state, tap_stream_id, 'BatchIDs')
current_bookmark = singer.get_bookmark(raw_state, tap_stream_id, 'JobHighestBookmarkSeen')
state = singer.write_bookmark(state, tap_stream_id, 'JobID', job_id)
state = singer.write_bookmark(state, tap_stream_id, 'BatchIDs', batches)
state = singer.write_bookmark(state, tap_stream_id, 'JobHighestBookmarkSeen', current_bookmark)
if replication_method == 'INCREMENTAL':
replication_key = catalog_metadata.get((), {}).get('replication-key')
replication_key_value = singer.get_bookmark(raw_state,
tap_stream_id,
replication_key)
if version is not None:
state = singer.write_bookmark(
state, tap_stream_id, 'version', version)
if replication_key_value is not None:
state = singer.write_bookmark(
state, tap_stream_id, replication_key, replication_key_value)
elif replication_method == 'FULL_TABLE' and version is None:
state = singer.write_bookmark(state, tap_stream_id, 'version', version)
return state
# pylint: disable=undefined-variable
示例7: main_impl
# 需要导入模块: from singer import metadata [as 别名]
# 或者: from singer.metadata import get [as 别名]
def main_impl():
args = singer_utils.parse_args(REQUIRED_CONFIG_KEYS)
CONFIG.update(args.config)
sf = None
try:
sf = Salesforce(
refresh_token=CONFIG['refresh_token'],
sf_client_id=CONFIG['client_id'],
sf_client_secret=CONFIG['client_secret'],
quota_percent_total=CONFIG.get('quota_percent_total'),
quota_percent_per_run=CONFIG.get('quota_percent_per_run'),
is_sandbox=CONFIG.get('is_sandbox'),
select_fields_by_default=CONFIG.get('select_fields_by_default'),
default_start_date=CONFIG.get('start_date'),
api_type=CONFIG.get('api_type'))
sf.login()
if args.discover:
do_discover(sf)
elif args.properties:
catalog = args.properties
state = build_state(args.state, catalog)
do_sync(sf, catalog, state)
finally:
if sf:
if sf.rest_requests_attempted > 0:
LOGGER.debug(
"This job used %s REST requests towards the Salesforce quota.",
sf.rest_requests_attempted)
if sf.jobs_completed > 0:
LOGGER.debug(
"Replication used %s Bulk API jobs towards the Salesforce quota.",
sf.jobs_completed)
if sf.login_timer:
sf.login_timer.cancel()
示例8: log_backoff_attempt
# 需要导入模块: from singer import metadata [as 别名]
# 或者: from singer.metadata import get [as 别名]
def log_backoff_attempt(details):
LOGGER.info("ConnectionError detected, triggering backoff: %d try", details.get("tries"))
示例9: check_rest_quota_usage
# 需要导入模块: from singer import metadata [as 别名]
# 或者: from singer.metadata import get [as 别名]
def check_rest_quota_usage(self, headers):
match = re.search('^api-usage=(\d+)/(\d+)$', headers.get('Sforce-Limit-Info'))
if match is None:
return
remaining, allotted = map(int, match.groups())
LOGGER.info("Used %s of %s daily REST API quota", remaining, allotted)
percent_used_from_total = (remaining / allotted) * 100
max_requests_for_run = int((self.quota_percent_per_run * allotted) / 100)
if percent_used_from_total > self.quota_percent_total:
total_message = ("Salesforce has reported {}/{} ({:3.2f}%) total REST quota " +
"used across all Salesforce Applications. Terminating " +
"replication to not continue past configured percentage " +
"of {}% total quota.").format(remaining,
allotted,
percent_used_from_total,
self.quota_percent_total)
raise TapSalesforceQuotaExceededException(total_message)
elif self.rest_requests_attempted > max_requests_for_run:
partial_message = ("This replication job has made {} REST requests ({:3.2f}% of " +
"total quota). Terminating replication due to allotted " +
"quota of {}% per replication.").format(self.rest_requests_attempted,
(self.rest_requests_attempted / allotted) * 100,
self.quota_percent_per_run)
raise TapSalesforceQuotaExceededException(partial_message)
# pylint: disable=too-many-arguments
示例10: _get_selected_properties
# 需要导入模块: from singer import metadata [as 别名]
# 或者: from singer.metadata import get [as 别名]
def _get_selected_properties(self, catalog_entry):
mdata = metadata.to_map(catalog_entry['metadata'])
properties = catalog_entry['schema'].get('properties', {})
return [k for k in properties.keys()
if singer.should_sync_field(metadata.get(mdata, ('properties', k), 'inclusion'),
metadata.get(mdata, ('properties', k), 'selected'),
self.select_fields_by_default)]
示例11: get_start_date
# 需要导入模块: from singer import metadata [as 别名]
# 或者: from singer.metadata import get [as 别名]
def get_start_date(self, state, catalog_entry):
catalog_metadata = metadata.to_map(catalog_entry['metadata'])
replication_key = catalog_metadata.get((), {}).get('replication-key')
return (singer.get_bookmark(state,
catalog_entry['tap_stream_id'],
replication_key) or self.default_start_date)
示例12: is_selected
# 需要导入模块: from singer import metadata [as 别名]
# 或者: from singer.metadata import get [as 别名]
def is_selected(cls, stream_name):
stream = cls.get_catalog_entry(stream_name)
stream_metadata = metadata.to_map(stream.metadata)
return metadata.get(stream_metadata, (), 'selected')
示例13: clean_state
# 需要导入模块: from singer import metadata [as 别名]
# 或者: from singer.metadata import get [as 别名]
def clean_state(state):
""" Clear deprecated keys out of state. """
for stream, bookmark_map in state.get("bookmarks", {}).items():
if "last_sync_duration" in bookmark_map:
LOGGER.info("{} - Removing last_sync_duration from state.".format(stream))
state["bookmarks"][stream].pop("last_sync_duration", None)
示例14: lift_properties_and_versions
# 需要导入模块: from singer import metadata [as 别名]
# 或者: from singer.metadata import get [as 别名]
def lift_properties_and_versions(record):
for key, value in record.get('properties', {}).items():
computed_key = "property_{}".format(key)
versions = value.get('versions')
record[computed_key] = value
if versions:
if not record.get('properties_versions'):
record['properties_versions'] = []
record['properties_versions'] += versions
return record
#pylint: disable=line-too-long
示例15: gen_request
# 需要导入模块: from singer import metadata [as 别名]
# 或者: from singer.metadata import get [as 别名]
def gen_request(STATE, tap_stream_id, url, params, path, more_key, offset_keys, offset_targets):
if len(offset_keys) != len(offset_targets):
raise ValueError("Number of offset_keys must match number of offset_targets")
if singer.get_offset(STATE, tap_stream_id):
params.update(singer.get_offset(STATE, tap_stream_id))
with metrics.record_counter(tap_stream_id) as counter:
while True:
data = request(url, params).json()
for row in data[path]:
counter.increment()
yield row
if not data.get(more_key, False):
break
STATE = singer.clear_offset(STATE, tap_stream_id)
for key, target in zip(offset_keys, offset_targets):
if key in data:
params[target] = data[key]
STATE = singer.set_offset(STATE, tap_stream_id, target, data[key])
singer.write_state(STATE)
STATE = singer.clear_offset(STATE, tap_stream_id)
singer.write_state(STATE)