记录器无法在集群上的Spark UDF中运行

时间:2018-09-13 06:59:11

标签: scala apache-spark hadoop user-defined-functions

我已经在UDF中放置了log.info语句,但是在群集上却失败了。当地工作正常。这是代码段:

def relType = udf((colValue: String, relTypeV: String) => {
var relValue = "NA"
val relType = relTypeV.split(",").toList
val relTypeMap = relType.map { col =>
  val split = col.split(":")
  (split(0), split(1))

}.toMap

//    val keySet = relTypeMap
relTypeMap.foreach { x =>
  if ((x._1 != null || colValue != null || x._1.trim() != "" || colValue.trim() != "") && colValue.equalsIgnoreCase(x._1)) {
    relValue = relTypeMap.getOrElse(x._1, "NA")
    log.info("testing.........")
  }
}
relValue
})

此外,当我在UDF中调用任何函数并使用log语句时,日志不会在群集中打印,并且也可以正常工作。

1 个答案:

答案 0 :(得分:-1)

log4j.appender.myConsoleAppender=org.apache.log4j.ConsoleAppender
log4j.appender.myConsoleAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.myConsoleAppender.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss} %p %c{1}: %m%n


log4j.appender.RollingAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.RollingAppender.File=src//main//resources//spark.log
log4j.appender.RollingAppender.DatePattern='.'yyyy-MM-dd
log4j.appender.RollingAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.RollingAppender.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss} %p %c{1}: %m%n

log4j.appender.RollingAppenderU=org.apache.log4j.DailyRollingFileAppender
log4j.appender.RollingAppenderU.File=src//main//resources//sparkU.log
log4j.appender.RollingAppenderU.DatePattern='.'yyyy-MM-dd
log4j.appender.RollingAppenderU.layout=org.apache.log4j.PatternLayout
log4j.appender.RollingAppenderU.layout.ConversionPattern=%d{yyyy/MM/dd HH:mm:ss} %p %c{1}: %m%n


# By default, everything goes to console and file
log4j.rootLogger=INFO, RollingAppender, myConsoleAppender

# My custom logging goes to another file
log4j.logger.myLogger=INFO, RollingAppenderU

# The noisier spark logs go to file only
log4j.logger.spark.storage=INFO, RollingAppender
log4j.additivity.spark.storage=false
log4j.logger.spark.scheduler=INFO, RollingAppender
log4j.additivity.spark.scheduler=false
log4j.logger.spark.CacheTracker=INFO, RollingAppender
log4j.additivity.spark.CacheTracker=false
log4j.logger.spark.CacheTrackerActor=INFO, RollingAppender
log4j.additivity.spark.CacheTrackerActor=false
log4j.logger.spark.MapOutputTrackerActor=INFO, RollingAppender
log4j.additivity.spark.MapOutputTrackerActor=false
log4j.logger.spark.MapOutputTracker=INFO, RollingAppender
log4j.additivty.spark.MapOutputTracker=false