Не удалось отфильтровать строки в базе данных cosmos с помощью spark-cosmos-connector - PullRequest
0 голосов
/ 25 января 2019

Я пытаюсь отфильтровать строки набора данных cosmos db. Я создаю представление для набора данных. Но всякий раз, когда мой запрос содержит предложение where, он не выполняется с NPE.

Сбой запроса ниже:

ds2 = spark.sql("select name.`$v` as fruits from tmp where name.`$v` ='JK1'").show;

, тогда как приведенный ниже запрос работает нормально:

ds2 = spark.sql("select name.`$v` as fruits from tmp");

Трассировка стека исключений:

execute, tree:
Exchange SinglePartition
+- *HashAggregate(keys=[], functions=[partial_count(1)], output= 
[count#69L])
  +- *Project
  +- *Filter (($v#1.name.$v = JK1) && isnotnull($v#1))
     +- *Scan com.microsoft.azure.cosmosdb.spark.schema.CosmosDBRelation@dfd5fb1f [$v#1] PushedFilters: [IsNotNull($v)], ReadSchema: struct<>
Exception in thread "main" java.lang.NullPointerException
at java.io.StringReader.<init>(StringReader.java:50)
at org.json.JSONTokener.<init>(JSONTokener.java:84)
at org.json.JSONObject.<init>(JSONObject.java:321)
at com.microsoft.azure.documentdb.JsonSerializable.<init>(JsonSerializable.java:74)
at com.microsoft.azure.documentdb.internal.query.PartitionedQueryExecutionInfo.<init>(PartitionedQueryExecutionInfo.java:32)
at com.microsoft.azure.documentdb.DocumentClient.readPartitionKeyRanges(DocumentClient.java:1890)
at com.microsoft.azure.cosmosdb.spark.CosmosDBConnection.getAllPartitions(CosmosDBConnection.scala:147)
at com.microsoft.azure.cosmosdb.spark.partitioner.CosmosDBPartitioner.computePartitions(CosmosDBPartitioner.scala:49)
at com.microsoft.azure.cosmosdb.spark.rdd.CosmosDBRDD.getPartitions(CosmosDBRDD.scala:64)
at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:252)
at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:250)

Зависимость:

<dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>azure-documentdb</artifactId>
        <version>2.1.0</version>
    </dependency>
    <dependency>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>azure-cosmosdb-spark_2.2.0_2.11</artifactId>
        <version>1.0.0</version>
        <exclusions>
            <exclusion>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>azure-documentdb</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>azure-documentdb-rx</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

Пример данных в наборе данных:

+---------------+
|           name|
+---------------+
|           null|
|        Ker on|
|            JK1|
|           null|
|     Jack    Kr|
|     tarry Keon|
|           null|
|           null|
+---------------+

Схема для набора данных космоса:

    root
    |-- $t: integer (nullable = true)
    |-- $v: struct (nullable = true)
    |    |-- fruit: struct (nullable = true)
    |    |    |-- $t: integer (nullable = true)
    |    |    |-- $v: string (nullable = true)
    |    |-- _id: struct (nullable = true)
    |    |    |-- $t: integer (nullable = true)
    |    |    |-- $v: string (nullable = true)
    |-- _attachments: string (nullable = true)
    |-- _etag: string (nullable = true)
    |-- _rid: string (nullable = true)
    |-- _self: string (nullable = true)
    |-- _ts: integer (nullable = true)
    |-- id: string (nullable = true)
...