import os START_TO_CLOSE_TIMEOUT = 18000 # Report type options SKIP_UNLOAD = 'skip_unload' UPDATE_STATUS_ONLY = 'update_status_only' TURN_UP_WRITE_CAPACITY_ONLY = 'turn_up_write_capacity' TURN_DOWN_WRITE_CAPACITY_ONLY = 'turn_down_write_capacity' # Environment variables env_aws_access_key_id = os.getenv('AWS_ACCESS_KEY_ID') env_aws_secret_access_key = os.getenv('AWS_SECRET_ACCESS_KEY') env = os.getenv('Environment') env_processing_accounting_sns_topic = os.getenv( 'PROCESSING_ACCOUNTING_SNS_TOPIC') STATUS_GENERATING = 'GENERATING' STATUS_GENERATED = 'GENERATED' STATUS_FAILED = 'FAILED' STATUS_PENDING = 'PENDING' # Dynamodb throughput READ_CAPACITY_UNITS = 5 HIGH_WRITE_CAPACITY_UNITS = 100 LOW_WRITE_CAPACITY_UNITS = 20 # Schematized file types SCHEMATIZED_FILE_FORMAT_AVRO = 'avro' # Default settings report_bucket = os.getenv('ACCOUNTING_STATEMENT_EXPORT_BUCKET') raw_file_format = 'tsv' schematized_file_format = 'avro' schematized_file_number_format = 'us' schematized_file_transaction_type = 'all' TRACK_ARTISTS_AGGREGATION_TABLE_NAME = 'dim_track_artists_aggregated_temp' hdfs_staging_path = ( 'hdfs:///{env}-statement-detail-export/{{params}}/' 'schematized_files').format(env=env) hdfs_staging_path_txt_files = ( 'hdfs:///{env}-statement-detail-export/{{params}}/' 'txt_files').format(env=env) config = { 'emr': { 'emr.tag_name': 'account_statement_exports', 'emr.ec2_instance_name': 'report_generation', 'emr.logs': ( 's3://{env}-statement-detail-exports/emr_logs/').format( env=env), 'hql_path': ( 's3://{env}-statement-detail-exports/emr/hql/' 'convert_csv_to_avro{{key}}.hql').format(env=env), 'hql': { 'setting': ( 'set hive.stats.autogather=false;' 'set mapred.map.tasks.speculative.execution=false;' 'set mapred.reduce.tasks.speculative.execution=false;' 'set hive.exec.max.created.files=10000000;' 'set hive.exec.dynamic.partition=true;' 'set hive.exec.dynamic.partition.mode=nonstrict;' 'set hive.exec.max.dynamic.partitions.pernode=10000000;' 'set hive.exec.max.dynamic.partitions=50000000;' 'set mapreduce.map.memory.mb=5120;' 'set mapreduce.reduce.memory.mb=5120;' 'set mapred.child.java.opts=-Xmx4608m -XX:+UseConcMarkSweepGC;' 'set mapreduce.reduce.java.opts=-Xmx4608m;' 'set hive.exec.reducers.bytes.per.reducer=104857600;'), 'drop_accounting_statement_export': ( 'drop table if exists accounting_statement_export{key};'), 'create_accounting_statement_export': ( 'create external table accounting_statement_export{key} ( ' 'period string, ' 'activity_period string, ' 'dms string, ' 'territory string, ' 'orchard_upc string, ' 'manufacturer_upc string, ' 'label_catalog string, ' 'product_code string, ' 'subaccount string, ' 'imprint_label string, ' 'artist_name string, ' 'release_name string, ' 'track_name string, ' 'isrc string, ' 'volume string, ' 'track_number string, ' 'quantity string, ' 'unit_price string, ' 'gross string, ' 'trans_type string, ' 'transactiontypedesc string, ' 'adjusted_gross string, ' 'split_rate string, ' 'label_share_net_receipts string, ' 'ringtone_publishing string, ' 'cloud_publishing string, ' 'publishing string, ' 'mech_administrative_fee string, ' 'subaccount_label_share_net_receipts string, ' 'preferred_currency string, ' 'statement_detail_id string, ' 'isdistributor string, ' 'physical_product_type string, ' 'physical_product_format string, ' 'display_configuration string, ' 'track_artists string, ' 'original_price string, ' 'discount string, ' 'user_id_type string) ' 'row format delimited fields terminated by "\007" ' 'location "${{INPUT}}";'), 'drop_accounting_statement_export_avro': ( 'drop table if exists accounting_statement_export_avro{key};'), 'write_avro_files': ( 'insert overwrite table ' 'accounting_statement_export_avro{key} ' 'partition (user_id_type) ' 'select ' 'period, ' 'activity_period, ' 'dms, ' 'territory, ' 'orchard_upc, ' 'manufacturer_upc, ' 'label_catalog, ' 'product_code, ' 'subaccount, ' 'imprint_label, ' 'artist_name, ' 'release_name, ' 'track_name, ' 'isrc, ' 'volume, ' 'track_number, ' 'quantity, ' 'unit_price, ' 'gross, ' 'trans_type, ' 'transactiontypedesc, ' 'adjusted_gross, ' 'split_rate, ' 'label_share_net_receipts, ' 'ringtone_publishing, ' 'cloud_publishing, ' 'publishing, ' 'mech_administrative_fee, ' 'subaccount_label_share_net_receipts, ' 'preferred_currency, ' 'statement_detail_id, ' 'isdistributor, ' 'physical_product_type, ' 'physical_product_format, ' 'display_configuration, ' 'track_artists, ' 'original_price, ' 'discount, ' 'user_id_type' ' from accounting_statement_export{key};'), 'create_avro_table': ( 'CREATE external TABLE accounting_statement_export_avro{key}' ' PARTITIONED BY (user_id_type string) ' 'ROW FORMAT ' 'SERDE \'org.apache.hadoop.hive.serde2.avro.AvroSerDe\' ' 'STORED AS INPUTFORMAT \'' 'org.apache.hadoop.hive.ql.io.avro.AvroContainerInputFormat\' ' 'OUTPUTFORMAT \'' 'org.apache.hadoop.hive.ql.io.avro.AvroContainerOutputFormat\'' ' LOCATION "${{OUTPUT}}" ' 'TBLPROPERTIES ( ' '\'avro.schema.literal\'=\'{{ ' '"namespace": "orchard.accounting", ' '"name": "accounting_statement_export", ' '"type": "record", ' '"fields": [{{"name": "period", "type": "string"}},' '{{"name": "activity_period", "type": "string"}},' '{{"name": "dms", "type": "string"}},' '{{"name": "territory", "type": "string"}},' '{{"name":"orchard_upc","type":"string"}},' '{{"name":"manufacturer_upc","type":"string"}},' '{{"name":"label_catalog","type":"string"}},' '{{"name":"product_code","type":"string"}},' '{{"name":"subaccount","type":"string"}},' '{{"name":"imprint_label","type":"string"}},' '{{"name":"artist_name","type":"string"}},' '{{"name":"release_name","type":"string"}},' '{{"name":"track_name","type":"string"}},' '{{"name":"isrc","type":"string"}},' '{{"name":"volume","type":"string"}},' '{{"name":"track_number","type":"string"}},' '{{"name":"quantity","type":"string"}},' '{{"name":"unit_price","type":"string"}},' '{{"name":"gross","type":"string"}},' '{{"name":"trans_type","type":"string"}},' '{{"name":"transactiontypedesc","type":"string"}},' '{{"name":"adjusted_gross","type":"string"}},' '{{"name":"split_rate","type":"string"}},' '{{"name":"label_share_net_receipts","type":"string"}},' '{{"name":"ringtone_publishing","type":"string"}},' '{{"name":"cloud_publishing","type":"string"}},' '{{"name":"publishing","type":"string"}},' '{{"name":"mech_administrative_fee","type":"string"}},' '{{"name":"subaccount_label_share_net_receipts",' '"type":"string"}},' '{{"name":"preferred_currency","type":"string"}},' '{{"name":"statement_detail_id","type":"string"}},' '{{"name":"isdistributor","type":"string"}},' '{{"name":"physical_product_type","type":"string"}},' '{{"name":"physical_product_format","type":"string"}},' '{{"name":"display_configuration","type":"string"}},' '{{"name":"track_artists","type":"string"}},' '{{"name":"original_price","type":"string"}},' '{{"name":"discount","type":"string"}}' '] ' '}}\');' ) } }, 'cross_labels_raw_files_path': ( 's3://{bucket}/snowflake_raw_data/{{params}}/' ).format(bucket=report_bucket), 'raw_files_path': ( 's3://{bucket}/snowflake_raw_data/{{params}}/' ).format(bucket=report_bucket), 'schematized_file_path': ( 's3://{bucket}/schematized_files/{{params}}').format( bucket=report_bucket), 'schema': { 'doc': 'Accounting Statement Export', 'name': 'Accounting Statement Export', 'namespace': 'test', 'type': 'record', 'fields': [ {'name': 'period', 'type': 'string'}, {'name': 'activity_period', 'type': 'string'}, {'name': 'dms', 'type': 'string'}, {'name': 'territory', 'type': 'string'}, {'name': 'orchard_upc', 'type': 'string'}, {'name': 'manufacturer_upc', 'type': 'string'}, {'name': 'label_catalog', 'type': 'string'}, {'name': 'subaccount', 'type': 'string'}, {'name': 'imprint_label', 'type': 'string'}, {'name': 'artist_name', 'type': 'string'}, {'name': 'release_name', 'type': 'string'}, {'name': 'track_name', 'type': 'string'}, {'name': 'isrc', 'type': 'string'}, {'name': 'volume', 'type': 'string'}, {'name': 'track_number', 'type': 'string'}, {'name': 'quantity', 'type': 'string'}, {'name': 'unit_price', 'type': 'string'}, {'name': 'gross', 'type': 'string'}, {'name': 'trans_type', 'type': 'string'}, {'name': 'adjusted_gross', 'type': 'string'}, {'name': 'split_rate', 'type': 'string'}, {'name': 'label_share_net_receipts', 'type': 'string'}, {'name': 'ringtone_publishing', 'type': 'string'}, {'name': 'cloud_publishing', 'type': 'string'}, {'name': 'publishing', 'type': 'string'}, {'name': 'mech_administrative_fee', 'type': 'string'}, {'name': 'subaccount_label_share_net_receipts', 'type': 'string'}, {'name': 'preferred_currency', 'type': 'string'}, {'name': 'statement_detail_id', 'type': 'string'}, {'name': 'isdistributor', 'type': 'string'}, {'name': 'user_id_type', 'type': 'string'} ] } }