AWS Glue爬虫默认情况下只爬取列名而不是数据。要使爬虫爬取数据,需要在爬虫的配置中添加“--update-all-ux”参数。例如,如果你使用Python编写的AWS Glue爬虫,可以在您的脚本中添加以下代码片段:
import sys
from awsglue.utils import getResolvedOptions
args = getResolvedOptions(sys.argv, ['JOB_NAME'])
glueContext = GlueContext(SparkContext.getOrCreate())
crawler = glueContext.create_dynamic_frame_from_options(
connection_options={
'path': 's3://example-bucket/path/to/data'
},
format='csv',
transformation_ctx='crawler'
)
crawler.toDF().show()
# Add the following line to enable crawling of data
crawler_options = crawler.toDF().options
crawler_options['updateSchemaInCatalog'] = 'true'
crawler_options['optionFiles'] = '/tmp/options.json'
crawler.toDF(**crawler_options).show()
在此示例中,爬虫从S3存储桶中加载CSV格式的数据,并使用show()
方法显示数据。添加crawler_options
变量并将'updateSchemaInCatalog'
选项设置为'true'
来启用数据爬虫。原理是在AWS Glue数仓中更新爬取到的数据结构,以便进一步使用。