Поскольку мне нужны данные, совместимые со всеми схемами, по умолчанию используется размер сэмпла 10000. Если я его включу, это потребует большой производительности и времени. Я хочу преобразовать данные в полную json без какой-либо схемы. Есть ли простой способ сделать это? Спасибо
import com.cd.flow.core.utils.ResourcesUtils
import org.apache.log4j.{Level, Logger}
import org.apache.spark.sql.SparkSession
object TestMogonToString {
Logger.getRootLogger.setLevel(Level.WARN)
def main(args: Array[String]): Unit = {
val m6PropValues = ResourcesUtils.getMogodbPropValues("ds6uri", "ds6database")
val spark = SparkSession.builder.master("local[*]").appName(this.getClass.getSimpleName) .getOrCreate()
import spark.implicits._
val m_sql = "[{$match:{'updateTime':{'$gte':'2020-01-08 00:00:00','$lte':'2020-01-08 23:59:59'}}}]"
println("m_sql", m_sql)
val lxjStoreMongoDF = spark.read.format("com.mongodb.spark.sql.DefaultSource")
.option("spark.mongodb.input.uri", m6PropValues._1).option("spark.mongodb.input.database", m6PropValues._2)
.option("collection", "order").option("pipeline", m_sql)/*.schema(structureSchema)*/.load()
lxjStoreMongoDF.show()
lxjStoreMongoDF.printSchema()
/**
* +--------------------+-------------+--------+---------+---------------+----------+----------------+......
* | _id|activityPrice| brandId|brandName|cancelBigReason|cancelNote|cancelOperribute|......
* +--------------------+-------------+--------+---------+---------------+----------+----------------+......
* |[5e1471dd666bb700...| 0|26000252| 奈雪の茶| 0| | null fals......
*---------------------------------------------------------------split
* root
* |-- _id: struct (nullable = true)
* | |-- oid: string (nullable = true)
* |-- orderDrivers: array (nullable = true)
* | |-- element: struct (containsNull = true)
* | | |-- name: string (nullable = true)
* | | |-- phone: string (nullable = true)
* |-- orderId: integer (nullable = true)
* |-- orderNo: string (nullable = true)
* |-- orderPreferentials: array (nullable = true)
* | |-- element: struct (containsNull = true)
* | | |-- childType: integer (nullable = true)
* | | |-- pid: string (nullable = true)
* ..........
*/
//I want that
/**
* +--------------------+---------
* | jsonstring |....
* +--------------------+---------
* |{_id:100,activityPrice:xx.....}|....
*---------------------------------------------------------------split
* root
* |-- jsonstring: string (nullable = true)
* ..........
*/
}
}