简体   繁体   English

py4j.Py4JException:方法和([class java.lang.String])不存在

[英]py4j.Py4JException: Method and([class java.lang.String]) does not exist

I am spark dataframe with below schema.我是 spark dataframe,具有以下架构。

-root
 |-- ME_KE: string (nullable = true)
 |-- CSPD_CAT: string (nullable = true)
 |-- EFF_DT: string (nullable = true)
 |-- TER_DT: string (nullable = true)
 |-- CREATE_DTM: string (nullable = true)
 |-- ELIG_IND: string (nullable = true)

Basically I am trying to convert spark SQL code into SQL on directly on dataframe.基本上我正在尝试将 spark SQL 代码直接在 dataframe 上转换为 SQL。

df=spark.read.format('csv').load(SourceFilesPath+"\\cutdetl.csv",infraSchema=True,header=True)
df.createOrReplaceTempView("cutdetl")

spark.sql(f"""select
              me_ke,
              eff_dt,
              ter_dt,
              create_dtm
              from
              cutdetl
              where
              (elig_ind = 'Y') and
              ((to_date({start_dt},'dd-mon-yyyy') between eff_dt and ter_dt) or
              (eff_dt between to_date({start_dt}'dd-mon-yyyy') and to_date({end_dt},'dd-mon-yyyy'))
""")

Below is the code I have tried.下面是我试过的代码。

df1=df.select("me_ke","eff_dt","ter_dt","elig_ind")
      .where(col("elig_ind")=="Y" & (F.to_date('31-SEP-2022', dd-mon-yyyy')
      .between(col("mepe_eff_dt"),col("mepe_term_dt"))) | 
      (F.to_date(col("eff_dt"))
      .between(F.to_date('31-DEC-2022'),F.to_date('31-DEC-2022'))))

I am getting below error:我收到以下错误:

py4j.Py4JException: Method and([class java.lang.String]) does not exist``` 

Could anyone help with converting above code to dataframe level SQL

I'd go like this我会像这样 go

from pyspark.sql.functions import col

df=spark.read.format('csv').load(SourceFilesPath+"\\cutdetl.csv",infraSchema=True,header=True)
df.createOrReplaceTempView("cutdetl")

df1 = df.filter(col("elig_ind") == "Y")
df1 = df1.filter((col("eff_dt").between(f"to_date({start_dt},'dd-mon-yyyy')", f"to_date({end_dt},'dd-mon-yyyy')")) | 
               (f"to_date({start_dt},'dd-mon-yyyy')".between(col("eff_dt"), col("ter_dt"))))
df1 = df1.select("me_ke", "eff_dt", "ter_dt", "create_dtm")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 py4j.Py4JException:方法splits([])不存在 - py4j.Py4JException: Method splits([]) does not exist UDF的Pyspark错误:py4j.Py4JException:方法__getnewargs __([])不存在错误 - Pyspark error with UDF: py4j.Py4JException: Method __getnewargs__([]) does not exist error Spark 1.4.1 py4j.Py4JException:方法read([])不存在 - Spark 1.4.1 py4j.Py4JException: Method read([]) does not exist pyspark Py4J 错误使用 canopy :PythonAccumulatorV2([class java.lang.String, class java.lang.Integer, class java.lang.String]) 不存在 - pyspark Py4J error using canopy :PythonAccumulatorV2([class java.lang.String, class java.lang.Integer, class java.lang.String]) does not exist Spark DF 枢轴错误:方法枢轴([类 java.lang.String,类 java.lang.String])不存在 - Spark DF pivot error: Method pivot([class java.lang.String, class java.lang.String]) does not exist Py4JException:构造函数 org.apache.spark.sql.SparkSession([class org.apache.spark.SparkContext,class java.util.HashMap])不存在 - Py4JException: Constructor org.apache.spark.sql.SparkSession([class org.apache.spark.SparkContext, class java.util.HashMap]) does not exist py4j.protocol.Py4JJavaError java.lang.NoSuchFieldError: JAVA_9 - py4j.protocol.Py4JJavaError java.lang.NoSuchFieldError: JAVA_9 py4j.protocol.Py4JError: org.apache.spark.api.python.PythonUtils.getEncryptionEnabled 在 JVM 中不存在 - py4j.protocol.Py4JError: org.apache.spark.api.python.PythonUtils.getEncryptionEnabled does not exist in the JVM Pyspark - withColumn + when with variable give "Method or([class java.lang.Boolean]) does not exist" - Pyspark - withColumn + when with variable give "Method or([class java.lang.Boolean]) does not exist" JPype1=0.7.0: TypeError: Unable to convert str ro java type class java.lang.String - JPype1=0.7.0: TypeError: Unable to convert str ro java type class java.lang.String
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM