首页 > 解决方案 > 根据特定 id 过滤掉行 - Glue Job

问题描述

我正在尝试创建一个通过一些转换运行的 AWS Glue 作业,但我陷入了一个特定的过滤规则。我试图过滤掉具有两个imp_click_campaign_id值的行:9247 和 9285。这两个 id 与我想删除的许多行相关联。

以下是我到目前为止实现的内容,第 37 行(Transform0)是我尝试过滤但我收到错误:py4j.protocol.Py4JJavaError: An error occurred while calling o190.pyWriteDynamicFrame. : org.apache.spark.SparkException: Job aborted due to stage failure: Task 8 in stage 2.0 failed 4 times, most recent failure: Lost task 8.3 in stage 2.0 (TID 53, 172.16.6.204, executor 3): java.lang.IllegalArgumentException: Can't get JDBC type for null尝试写入我的 JDBC 连接时。我认为这是因为我的过滤器不正确。

import sys
from awsglue.transforms import *
from awsglue.utils import getResolvedOptions
from pyspark.context import SparkContext
import pyspark.sql.functions as F
from awsglue.context import GlueContext
from awsglue.job import Job
from awsglue.dynamicframe import DynamicFrame

## @params: [JOB_NAME]
args = getResolvedOptions(sys.argv, ['JOB_NAME'])

sc = SparkContext()
glueContext = GlueContext(sc)
spark = glueContext.spark_session
job = Job(glueContext)
job.init(args['JOB_NAME'], args)
## @type: DataSource
## @args: [database = "pixel_data", table_name = "pixel_data_nicheresearch_internal", transformation_ctx = "datasource0"]
## @return: datasource0
## @inputs: []
datasource0 = glueContext.create_dynamic_frame.from_catalog(database = "pixel_data", table_name = "pixel_data_nicheresearch_internal", transformation_ctx = "datasource0")
## @type: ApplyMapping
## @args: [mapping = [("conv_dttm", "string", "conv_dttm", "string"), ("imp_click_dttm", "string", "imp_click_dttm", "string"), ("cid", "string", "cid", "string"), ("imp_click_campaign_id", "long", "imp_click_campaign_id", "long"), ("campaign_name", "string", "campaign_name", "string"), ("imp_click_partner_id", "long", "imp_click_partner_id", "long"), ("partner_name", "string", "partner_name", "string"), ("imp_click_placement_id", "long", "imp_click_placement_id", "long"), ("placement_name", "string", "placement_name", "string"), ("custom_reference_id", "string", "custom_reference_id", "string"), ("imp_click_creative_id", "string", "imp_click_creative_id", "string"), ("goal_name", "string", "goal_name", "string"), ("description", "string", "description", "string"), ("conversion_type", "string", "conversion_type", "string"), ("conv_ip_address", "string", "conv_ip_address", "string"), ("conv_user_agent", "string", "conv_user_agent", "string"), ("custom_var_1", "string", "custom_var_1", "string"), ("custom_var_2", "string", "custom_var_2", "string"), ("custom_var_3", "string", "custom_var_3", "string"), ("custom_var_4", "string", "custom_var_4", "string"), ("conv_revenue", "double", "conv_revenue", "double"), ("idfa", "string", "idfa", "string"), ("sec_diff_utc", "long", "sec_diff_utc", "long"), ("deterministic_match", "long", "deterministic_match", "long"), ("high_probabilistic_match", "long", "high_probabilistic_match", "long"), ("probabilitstic_match", "long", "probabilitstic_match", "long"), ("ip_match", "long", "ip_match", "long"), ("conv_device_type", "string", "conv_device_type", "string"), ("placement_platform", "string", "placement_platform", "string"), ("hhid_match", "long", "hhid_match", "long"), ("click_custom_var_1", "string", "click_custom_var_1", "string"), ("click_custom_var_2", "string", "click_custom_var_2", "string"), ("click_custom_var_3", "string", "click_custom_var_3", "string"), ("click_custom_var_4", "string", "click_custom_var_4", "string"), ("imp_click_custom_var_1", "string", "imp_click_custom_var_1", "string"), ("imp_click_custom_var_2", "string", "imp_click_custom_var_2", "string"), ("imp_click_custom_var_3", "string", "imp_click_custom_var_3", "string"), ("imp_click_custom_var_4", "string", "imp_click_custom_var_4", "string"), ("partition_0", "string", "partition_0", "string")], transformation_ctx = "applymapping1"]
## @return: applymapping1
## @inputs: [frame = datasource0]
applymapping1 = ApplyMapping.apply(frame = datasource0, mappings = [("conv_dttm", "string", "conv_dttm", "string"), ("imp_click_dttm", "string", "imp_click_dttm", "string"), ("cid", "string", "cid", "string"), ("imp_click_campaign_id", "long", "imp_click_campaign_id", "long"), ("campaign_name", "string", "campaign_name", "string"), ("imp_click_partner_id", "long", "imp_click_partner_id", "long"), ("partner_name", "string", "partner_name", "string"), ("imp_click_placement_id", "long", "imp_click_placement_id", "long"), ("placement_name", "string", "placement_name", "string"), ("custom_reference_id", "string", "custom_reference_id", "string"), ("imp_click_creative_id", "string", "imp_click_creative_id", "string"), ("goal_name", "string", "goal_name", "string"), ("description", "string", "description", "string"), ("conversion_type", "string", "conversion_type", "string"), ("conv_ip_address", "string", "conv_ip_address", "string"), ("conv_user_agent", "string", "conv_user_agent", "string"), ("custom_var_1", "string", "custom_var_1", "string"), ("custom_var_2", "string", "custom_var_2", "string"), ("custom_var_3", "string", "custom_var_3", "string"), ("custom_var_4", "string", "custom_var_4", "string"), ("conv_revenue", "double", "conv_revenue", "double"), ("idfa", "string", "idfa", "string"), ("sec_diff_utc", "long", "sec_diff_utc", "long"), ("deterministic_match", "long", "deterministic_match", "long"), ("high_probabilistic_match", "long", "high_probabilistic_match", "long"), ("probabilitstic_match", "long", "probabilitstic_match", "long"), ("ip_match", "long", "ip_match", "long"), ("conv_device_type", "string", "conv_device_type", "string"), ("placement_platform", "string", "placement_platform", "string"), ("hhid_match", "long", "hhid_match", "long"), ("click_custom_var_1", "string", "click_custom_var_1", "string"), ("click_custom_var_2", "string", "click_custom_var_2", "string"), ("click_custom_var_3", "string", "click_custom_var_3", "string"), ("click_custom_var_4", "string", "click_custom_var_4", "string"), ("imp_click_custom_var_1", "string", "imp_click_custom_var_1", "string"), ("imp_click_custom_var_2", "string", "imp_click_custom_var_2", "string"), ("imp_click_custom_var_3", "string", "imp_click_custom_var_3", "string"), ("imp_click_custom_var_4", "string", "imp_click_custom_var_4", "string"), ("partition_0", "string", "partition_0", "string")], transformation_ctx = "applymapping1")
## @type: ResolveChoice
## @args: [choice = "make_cols", transformation_ctx = "resolvechoice2"]
## @return: resolvechoice2
## @inputs: [frame = applymapping1]
resolvechoice2 = ResolveChoice.apply(frame = applymapping1, choice = "make_cols", transformation_ctx = "resolvechoice2")
## @type: Filter
## @args: [f = <function>, transformation_ctx = "<transformation_ctx>"]
## @return: <output>
## @inputs: [frame = <frame>]
Transform0 = Filter.apply(frame = resolvechoice2, f = lambda row : (not(row["imp_click_campaign_id"] == 9427) or not(row["imp_click_campaign_id"] == 9285)), transformation_ctx = "Transform0")
## @type: DropNullFields
## @args: [transformation_ctx = "dropnullfields3"]
## @return: dropnullfields3
## @inputs: [frame = resolvechoice2]
dropnullfields3 = DropNullFields.apply(frame = Transform0, transformation_ctx = "dropnullfields3")
new_data_frame = DynamicFrame.fromDF(dropnullfields3.toDF().withColumn('final_description', F.coalesce(F.col('description'), F.col('goal_name'))), glueContext, 'df')
## @type: DataSink
## @args: [catalog_connection = "product-analytics-test", connection_options = {"dbtable": "conversions", "database": "pixel_data"}, transformation_ctx = "datasink4"]
## @return: datasink4
## @inputs: [frame = dropnullfields3]
datasink4 = glueContext.write_dynamic_frame.from_jdbc_conf(frame = new_data_frame, catalog_connection = "product-analytics-test", connection_options = {"dbtable": "conversions", "database": "pixel_data"}, transformation_ctx = "datasink4")
job.commit()

标签: aws-glue

解决方案


推荐阅读