我试图运行使用EXIST子句的查询:
select <...>
from A, B, C
where
A.FK_1 = B.PK and
A.FK_2 = C.PK and
exists (select A.ID from <subquery 1>) or
exists (select A.ID from <subquery 2>)
Run Code Online (Sandbox Code Playgroud)
不幸的是,这似乎不受支持.我也尝试用EXISTS
一个IN
子句替换该子句:
select <...>
from A, B, C
where
A.FK_1 = B.PK and
A.FK_2 = C.PK and
A.ID in (select ID from ...) or
A.ID in (select ID from ...)
Run Code Online (Sandbox Code Playgroud)
不幸的是,该IN
条款似乎也没有得到支持.
有关如何编写实现所需结果的SQL查询的任何想法?我原则上可以将该WHERE
条款建模为另一个条款,JOIN
而第二个OR
条款则可以模拟,UNION
但它看起来非常笨拙.
编辑:列出一些可能的解决方案.
解决方案1
select <...>
from A, …
Run Code Online (Sandbox Code Playgroud) 是否可以匹配Scala中的参数类型?假设我有一个函数接收两个参数:a value
和a type
.我想使用模式匹配来进行类型转换.
像这样的东西:
datatype match {
case IntegerType => return value.toInt
case FloatType => return value.toFloat
case StringType => return value
case DecimalType(_,_) => return BigDecimal(value) // this is not working
case _ => return strrepr
}
Run Code Online (Sandbox Code Playgroud)
这里DecimalType
接受两个参数来指定精度所需的精度.它可以是例如:
org.apache.spark.sql.types.DecimalType = DecimalType(10,2)
Run Code Online (Sandbox Code Playgroud)
我尝试了几个选项,似乎没有任何工作:
因为case DecimalType => return BigDecimal(value)
我得到:
error: pattern type is incompatible with expected type;
found : org.apache.spark.sql.types.DecimalType.type
required: org.apache.spark.sql.types.DataType
Note: if you intended to match against the class, try `case DecimalType(_,_)`
Run Code Online (Sandbox Code Playgroud)因为 …