开始使用免费开始使用

练习日志记录

启动时会执行以下代码:

import logging
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG,
                    format='%(levelname)s - %(message)s')

现在请练习这些日志记录操作。

本练习是课程的一部分

Python 中的 Spark SQL 入门

查看课程

练习说明

  • text_df 的列作为调试信息记录。
  • table1 是否已缓存作为信息记录。
  • text_df 的首行作为警告信息记录。
  • text_df 的指定列作为错误信息记录。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Log columns of text_df as debug message
____("text_df columns: %s", text_df.columns)

# Log whether table1 is cached as info message
____("table1 is cached: %s", spark.catalog.isCached(tableName="table1"))

# Log first row of text_df as warning message
____("The first row of text_df:\n %s", text_df.first())

# Log selected columns of text_df as error message
____("Selected columns: %s", text_df.select("id", "word"))
编辑并运行代码