You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@bahir.apache.org by emlaver <gi...@git.apache.org> on 2017/06/19 18:30:53 UTC

[GitHub] bahir pull request #45: [BAHIR-110] Implement _changes API for non-streaming...

GitHub user emlaver opened a pull request:

    https://github.com/apache/bahir/pull/45

    [BAHIR-110] Implement _changes API for non-streaming receiver

    See [JIRA-110](https://issues.apache.org/jira/browse/BAHIR-110)
    
    _What_
    
    Add support for _changes API for non-streaming (data frames and SQL temp. views) receiver.
    
    _How_
    - New CloudantConfig option `apiReceiver` for selecting _all_docs and _changes endpoint in Cloudant to Spark data frames and SQL temp tables
    - Default is `_all_docs` endpoint for non-streaming receiver
    - Base abstract config class that's extended by an all_docs class and _changes class
    - JsonStoreConfigManager includes new 'cloudant.apiReceiver' config option for selecting _all_docs and _changes endpoint in Cloudant to Spark data frames and SQL temp tables
    - Updated README with details for 'cloudant.apiReceiver' option
    
    _Testing_
    
    - Added base class ClientSparkFunSuite for setting up, creating, and loading sample data from flat files to test databases.
    - CloudantAllDocsDFSuite to test Spark data frames using the _all_docs endpoint.
    - CloudantChangesDFSuite to test Spark data frames using the _changes endpoint.
    - CloudantOptionSuite to verify Cloudant config options.
    - CloudantSparkSQLSuite to test Spark SQL temp views.
    
    Note: 27,378 lines added for the JSON files used in the testing suite.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/emlaver/bahir 110-implement-changes-api-in-receiver

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/bahir/pull/45.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #45
    
----
commit 065752978e7d826cd311df4c517044183db0c372
Author: Esteban Laver <em...@us.ibm.com>
Date:   2017-06-16T18:17:30Z

    Excluded scala flat files for testing from build

commit 751a5c7b876eca822e3047a609165505b5eadc4c
Author: Esteban Laver <em...@us.ibm.com>
Date:   2017-06-16T18:23:39Z

    Added MapReduce example, removed unused imports, and replaced SQL TEMP TABLE with TEMP VIEW

commit 39be19029a5b02820749ea7a5e19f345a4d74de0
Author: Esteban Laver <em...@us.ibm.com>
Date:   2017-06-19T15:22:41Z

    New CloudantConfig option `apiReceiver` for selecting _all_docs and _changes endpoint in Cloudant to Spark data frames and SQL temp tables
    - Default is `_all_docs` endpoint for non-streaming receiver
    - Base abstract config class that's extended by an all_docs class and _changes class
    - CloudantException thrown when required Spark Cloudant config option is empty or invalid
    - Updated scala style

commit b662611722d118800b1135ab69f02a979ebedb3c
Author: Esteban Laver <em...@us.ibm.com>
Date:   2017-06-19T15:23:28Z

    JsonStoreConfigManager: new 'cloudant.apiReceiver' config option for selecting _all_docs and _changes endpoint in Cloudant to Spark data frames and SQL temp tables
    - Throw CloudantException when spark config value is invalid or empty
    JsonStoreDataAccess: Added selector for use with _changes API and to filter out design docs
    JsonStoreRDD: Partition set to 1 for _changes API
    Updated Scala style in common classes:
    - Fixed ordering of imports
    - Added type notation
    - Removed redundant parenthesis

commit 4c8fc6bff81df034e789d2e782db11fca6e7cd84
Author: Esteban Laver <em...@us.ibm.com>
Date:   2017-06-19T15:25:28Z

    JSON files and logging properties for testing suite

commit a798f4cd1ef63f10a2f261f3c4460ef018d8d95d
Author: Esteban Laver <em...@us.ibm.com>
Date:   2017-06-19T15:28:02Z

    Testing suite:
    ClientSparkFunSuite for setting up, creating, and loading sample data from flat files to test databases.
    CloudantAllDocsDFSuite to test Spark data frames using the _all_docs endpoint.
    CloudantChangesDFSuite to test Spark data frames using the _changes endpoint.
    CloudantOptionSuite to verify Cloudant config options.
    CloudantSparkSQLSuite to test Spark SQL temp views.
    
    - Version 2.6.7 for jackson dependencies resolves "Incompatible Jackson version" during build
    - Cloudant set-up and database creation using cloudant-client library

commit c6ecb836ef0eb714398360b21ab95f1c18b762e1
Author: Esteban Laver <em...@us.ibm.com>
Date:   2017-06-19T15:28:23Z

    Updated README
    - New option 'cloudant.apiReceiver' for selecting _all_docs or _changes endpoint
    - Fixed links to source code files

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [BAHIR-110] Implement _changes API for non-streaming...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r128946219
  
    --- Diff: sql-cloudant/src/main/scala/org/apache/bahir/cloudant/internal/ChangesReceiver.scala ---
    @@ -0,0 +1,100 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.bahir.cloudant.internal
    +
    +import org.slf4j.{Logger, LoggerFactory}
    +import play.api.libs.json.Json
    +import scalaj.http._
    +
    +import org.apache.spark.SparkConf
    +import org.apache.spark.storage.StorageLevel
    +import org.apache.spark.streaming.receiver.Receiver
    +
    +import org.apache.bahir.cloudant.CloudantChangesConfig
    +import org.apache.bahir.cloudant.common._
    +
    +
    +class ChangesReceiver(config: CloudantChangesConfig)
    +  extends Receiver[String](StorageLevel.MEMORY_AND_DISK) {
    +
    +  def onStart() {
    +    // Start the thread that receives data over a connection
    +    new Thread("Cloudant Receiver") {
    +      override def run() { receive() }
    +    }.start()
    +  }
    +
    +  private def receive(): Unit = {
    +    // Get total number of docs in database using _all_docs endpoint
    +    val limit = new JsonStoreDataAccess(config)
    +      .getTotalRows(config.getTotalUrl, queryUsed = false)
    +
    +    // Get continuous _changes url
    +    val url = config.getChangesReceiverUrl.toString
    +    val selector: String = {
    +      "{\"selector\":" + config.getSelector + "}"
    +    }
    +
    +    var count = 0
    +    val clRequest: HttpRequest = config.username match {
    +      case null =>
    +        Http(url)
    +          .postData(selector)
    +          .timeout(connTimeoutMs = 1000, readTimeoutMs = 0)
    +          .header("Content-Type", "application/json")
    +          .header("User-Agent", "spark-cloudant")
    +      case _ =>
    +        Http(url)
    +          .postData(selector)
    +          .timeout(connTimeoutMs = 1000, readTimeoutMs = 0)
    +          .header("Content-Type", "application/json")
    +          .header("User-Agent", "spark-cloudant")
    +          .auth(config.username, config.password)
    +    }
    +
    +    clRequest.exec((code, headers, is) => {
    +      if (code == 200) {
    +        scala.io.Source.fromInputStream(is, "utf-8").getLines().foreach(line => {
    +          if (line.length() > 0) {
    +            val json = Json.parse(line)
    +            val jsonDoc = (json \ "doc").getOrElse(null)
    +            var doc = ""
    +            if(jsonDoc != null) {
    +              doc = Json.stringify(jsonDoc)
    +              // Verify that doc is not empty and is not deleted
    +              val deleted = (jsonDoc \ "_deleted").getOrElse(null)
    +              if(!doc.isEmpty && deleted == null) {
    +                store(doc)
    +                count += 1
    +              }
    +            }
    +          } else if (count >= limit) {
    --- End diff --
    
    Fixed in 8b40e38.
    
    



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [WIP] [BAHIR-110] Implement _changes API for non-streaming ...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    Build successful
     



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    Build successful
     



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r127890607
  
    --- Diff: sql-cloudant/src/main/scala/org/apache/bahir/cloudant/DefaultSource.scala ---
    @@ -98,29 +99,81 @@ class DefaultSource extends RelationProvider
     
           val config: CloudantConfig = JsonStoreConfigManager.getConfig(sqlContext, parameters)
     
    -      var allDocsDF: DataFrame = null
    +      var dataFrame: DataFrame = null
     
           val schema: StructType = {
             if (inSchema != null) {
               inSchema
    -        } else {
    -          val df = if (config.getSchemaSampleSize() ==
    -            JsonStoreConfigManager.ALL_DOCS_LIMIT &&
    +        } else if (!config.isInstanceOf[CloudantChangesConfig]
    +          || config.viewName != null || config.indexName != null) {
    +          val df = if (config.getSchemaSampleSize ==
    +            JsonStoreConfigManager.ALLDOCS_OR_CHANGES_LIMIT &&
                 config.viewName == null
                 && config.indexName == null) {
                 val cloudantRDD = new JsonStoreRDD(sqlContext.sparkContext, config)
    -            allDocsDF = sqlContext.read.json(cloudantRDD)
    -            allDocsDF
    +            dataFrame = sqlContext.read.json(cloudantRDD)
    +            dataFrame
               } else {
                 val dataAccess = new JsonStoreDataAccess(config)
                 val aRDD = sqlContext.sparkContext.parallelize(
    -                dataAccess.getMany(config.getSchemaSampleSize()))
    +                dataAccess.getMany(config.getSchemaSampleSize))
                 sqlContext.read.json(aRDD)
               }
               df.schema
    +        } else {
    +          /* Create a streaming context to handle transforming docs in
    +          * larger databases into Spark datasets
    +          */
    +          val ssc = new StreamingContext(sqlContext.sparkContext, Seconds(10))
    +          val streamingMap = {
    +            val selector = config.asInstanceOf[CloudantChangesConfig].getSelector
    +            if (selector != null) {
    +              Map(
    +                "database" -> config.getDbname,
    +                "selector" -> selector
    +              )
    +            } else {
    +              Map(
    +                "database" -> config.getDbname
    +              )
    +            }
    +          }
    +
    +          val changes = ssc.receiverStream(
    +            new CloudantReceiver(sqlContext.sparkContext.getConf, streamingMap))
    +          changes.persist(config.asInstanceOf[CloudantChangesConfig]
    +            .getStorageLevelForStreaming)
    +
    +          // Global RDD that's created from union of all RDDs
    +          var globalRDD = ssc.sparkContext.emptyRDD[String]
    +
    +          logger.info("Loading data from Cloudant using "
    +            + config.asInstanceOf[CloudantChangesConfig].getContinuousChangesUrl)
    +
    --- End diff --
    
    @mayya-sharipova Updates and fixes in c2c7fc4.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    @ckadner @ricellis @mayya-sharipova @yanglei99 Thanks for all your comments and time spent reviewing this large PR!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    @ckadner Do you have any additional comments? I'll rebase and squash the commits once @mayya-sharipova reviews the last commit.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [WIP] [BAHIR-110] Implement _changes API for non-streaming ...

Posted by ckadner <gi...@git.apache.org>.
Github user ckadner commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    @emlaver -- the most recent build ([77](http://169.45.79.58:8080/job/bahir_spark_pr_builder/77/)) ran with user/pwd env vars set ...
    
    ```
    Discovery completed in 185 milliseconds.
    Run starting. Expected test count is: 21
    CloudantOptionSuite:
    - invalid api receiver option throws an error message
    - empty username option throws an error message
    - empty password option throws an error message
    - empty databaseName throws an error message
    ClientSparkFunSuite:
    CloudantChangesDFSuite:
    - load and save data from Cloudant database
    - load and count data from Cloudant search index
    - load data and count rows in filtered dataframe
    - save filtered dataframe to database
    - save dataframe to database using createDBOnSave=true option
    - load and count data from view
    - load data from view with MapReduce function
    - load data and verify total count of selector, filter, and view option
    CloudantSparkSQLSuite:
    - verify results from temp view of database n_airportcodemapping
    - verify results from temp view of index in n_flight
    CloudantAllDocsDFSuite:
    - load and save data from Cloudant database
    - load and count data from Cloudant search index
    - load data and count rows in filtered dataframe
    - save filtered dataframe to database
    - save dataframe to database using createDBOnSave=true option
    - load and count data from view
    - load data from view with MapReduce function
    
    Run completed in 2 minutes, 58 seconds.
    Total number of tests run: 21
    Suites: completed 6, aborted 0
    Tests: succeeded 21, failed 0, canceled 0, ignored 0, pending 0
    
    All tests passed.
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by ckadner <gi...@git.apache.org>.
Github user ckadner commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r125737084
  
    --- Diff: sql-cloudant/src/main/scala/org/apache/bahir/cloudant/CloudantAllDocsConfig.scala ---
    @@ -0,0 +1,67 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.bahir.cloudant
    +
    +import org.apache.bahir.cloudant.common.JsonStoreConfigManager
    +
    +class CloudantAllDocsConfig(protocol: String, host: String, dbName: String,
    +                            indexName: String = null, viewName: String = null)
    +                           (username: String, password: String, partitions: Int,
    +                            maxInPartition: Int, minInPartition: Int, requestTimeout: Long,
    +                            bulkSize: Int, schemaSampleSize: Int,
    +                            createDBOnSave: Boolean, apiReceiver: String, selector: String,
    --- End diff --
    
    @mayya-sharipova -- code style guide calls for 100 character per line limit
    
    See: https://github.com/apache/bahir/blob/fd4c35fc9f7ebb57464d231cf5d66e7bc4096a1b/scalastyle-config.xml#L78


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [BAHIR-110] Implement _changes API for non-streaming...

Posted by ckadner <gi...@git.apache.org>.
Github user ckadner commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r122793307
  
    --- Diff: sql-cloudant/src/test/scala/org/apache/bahir/cloudant/TestUtils.scala ---
    @@ -0,0 +1,73 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.bahir.cloudant
    +
    +import java.io.File
    +
    +object TestUtils {
    +  // List of test databases to create from JSON flat files
    +  val testDatabasesList: List[String] = List(
    +    "n_airportcodemapping",
    +    "n_booking",
    +    "n_customer",
    +    "n_customersession",
    +    "n_flight",
    +    "n_flight2",
    +    "n_flightsegment"
    +  )
    +
    +  // Set CouchDB/Cloudant host, username and password for local testing
    +  private val host = System.getenv("DB_HOST")
    --- End diff --
    
    @emlaver -- could you prefix the environment variables with **CLOUDANT_** ?
    
    ```
    CLOUDANT_DB_HOST
    CLOUDANT_DB_USER
    CLOUDANT_DB_PASSWORD
    CLOUDANT_DB_PROTOCOL
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    Build successful
     



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    @ckadner Updated tests to check if env. variables CLOUDANT_USER and CLOUDANT_PASSWORD exist.  If they do not exist, all tests will be skipped in d57cfe7



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    
    Refer to this link for build results (access rights to CI server needed): 
    http://169.45.79.58:8080/job/bahir_spark_pr_builder/89/



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by ckadner <gi...@git.apache.org>.
Github user ckadner commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    ok to test


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by ricellis <gi...@git.apache.org>.
Github user ricellis commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126428690
  
    --- Diff: sql-cloudant/src/main/scala/org/apache/bahir/cloudant/CloudantConfig.scala ---
    @@ -30,81 +28,83 @@ import org.apache.bahir.cloudant.common._
     */
     
     class CloudantConfig(val protocol: String, val host: String,
    -    val dbName: String, val indexName: String = null, val viewName: String = null)
    +    val dbName: String, val indexName: String, val viewName: String)
         (implicit val username: String, val password: String,
         val partitions: Int, val maxInPartition: Int, val minInPartition: Int,
         val requestTimeout: Long, val bulkSize: Int, val schemaSampleSize: Int,
    -    val createDBOnSave: Boolean, val selector: String, val useQuery: Boolean = false,
    -    val queryLimit: Int)
    -    extends Serializable{
    +    val createDBOnSave: Boolean, val apiReceiver: String,
    +    val useQuery: Boolean = false, val queryLimit: Int)
    +    extends Serializable {
     
    -  private lazy val dbUrl = {protocol + "://" + host + "/" + dbName}
    +  lazy val dbUrl: String = {protocol + "://" + host + "/" + dbName}
     
       val pkField = "_id"
    -  val defaultIndex = "_all_docs" // "_changes" does not work for partition
    +  val defaultIndex: String = apiReceiver
       val default_filter: String = "*:*"
     
    -  def getContinuousChangesUrl(): String = {
    -    var url = dbUrl + "/_changes?include_docs=true&feed=continuous&heartbeat=3000"
    -    if (selector != null) {
    -      url = url + "&filter=_selector"
    -    }
    -    url
    -  }
    -
    -  def getSelector() : String = {
    -    selector
    -  }
    -
    -  def getDbUrl(): String = {
    +  def getDbUrl: String = {
         dbUrl
       }
     
    -  def getSchemaSampleSize(): Int = {
    +  def getSchemaSampleSize: Int = {
         schemaSampleSize
       }
     
    -  def getCreateDBonSave(): Boolean = {
    +  def getCreateDBonSave: Boolean = {
         createDBOnSave
       }
     
    -  def getTotalUrl(url: String): String = {
    -    if (url.contains('?')) {
    -      url + "&limit=1"
    -    } else {
    -      url + "?limit=1"
    -    }
    -  }
    -
    -  def getDbname(): String = {
    -    dbName
    -  }
    -
    -  def queryEnabled(): Boolean = {useQuery && indexName==null && viewName==null}
    -
    -  def allowPartition(queryUsed: Boolean): Boolean = {indexName==null && !queryUsed}
    -
    -  def getAllDocsUrl(limit: Int, excludeDDoc: Boolean = false): String = {
    +  def getLastNum(result: JsValue): JsValue = (result \ "last_seq").get
     
    +  /* Url containing limit for docs in a Cloudant database.
    +  * If a view is not defined, use the _all_docs endpoint.
    +  * @return url with one doc limit for retrieving total doc count
    +  */
    +  def getUrl(limit: Int, excludeDDoc: Boolean = false): String = {
         if (viewName == null) {
    -      val baseUrl = (
    -          if ( excludeDDoc) dbUrl + "/_all_docs?startkey=%22_design0/%22&include_docs=true"
    -          else dbUrl + "/_all_docs?include_docs=true"
    -          )
    -      if (limit == JsonStoreConfigManager.ALL_DOCS_LIMIT) {
    +      val baseUrl = {
    +        if (excludeDDoc) {
    +          dbUrl + "/_all_docs?startkey=%22_design0/%22&include_docs=true"
    --- End diff --
    
    See https://github.com/cloudant/java-cloudant/issues/344#issuecomment-276938689
    This `startkey` makes the assumption that no document IDs will start with upper case letters. Possibly one for another issue.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by ricellis <gi...@git.apache.org>.
Github user ricellis commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126407536
  
    --- Diff: sql-cloudant/README.md ---
    @@ -52,39 +51,71 @@ Here each subsequent configuration overrides the previous one. Thus, configurati
     
     
     ### Configuration in application.conf
    -Default values are defined in [here](cloudant-spark-sql/src/main/resources/application.conf).
    +Default values are defined in [here](src/main/resources/application.conf).
     
     ### Configuration on SparkConf
     
     Name | Default | Meaning
     --- |:---:| ---
    +cloudant.apiReceiver|"_all_docs"| API endpoint for RelationProvider when loading or saving data from Cloudant to DataFrames or SQL temporary tables. Select between "_all_docs" or "_changes" endpoint.
     cloudant.protocol|https|protocol to use to transfer data: http or https
    -cloudant.host||cloudant host url
    -cloudant.username||cloudant userid
    -cloudant.password||cloudant password
    +cloudant.host| |cloudant host url
    +cloudant.username| |cloudant userid
    +cloudant.password| |cloudant password
     cloudant.useQuery|false|By default, _all_docs endpoint is used if configuration 'view' and 'index' (see below) are not set. When useQuery is enabled, _find endpoint will be used in place of _all_docs when query condition is not on primary key field (_id), so that query predicates may be driven into datastore. 
     cloudant.queryLimit|25|The maximum number of results returned when querying the _find endpoint.
     jsonstore.rdd.partitions|10|the number of partitions intent used to drive JsonStoreRDD loading query result in parallel. The actual number is calculated based on total rows returned and satisfying maxInPartition and minInPartition
     jsonstore.rdd.maxInPartition|-1|the max rows in a partition. -1 means unlimited
     jsonstore.rdd.minInPartition|10|the min rows in a partition.
     jsonstore.rdd.requestTimeout|900000| the request timeout in milliseconds
     bulkSize|200| the bulk save size
    -schemaSampleSize| "-1" | the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    -createDBOnSave|"false"| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +schemaSampleSize|-1| the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    +createDBOnSave|false| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +
    +The `cloudant.apiReceiver` option allows for _changes or _all_docs API endpoint to be called while loading Cloudant data into Spark DataFrames or SQL Tables,
    +or saving data from DataFrames or SQL Tables to a Cloudant database.
    +
    +**Note:** When using `_changes` API, please consider: 
    +1. Results are partially ordered and may not be be presented in order in 
    +which documents were updated.
    +2. In case of shards' unavailability, you may see duplicate results (changes that have been seen already)
    +3. Can use `selector` option to filter Cloudant docs during load
    +4. Supports a real snapshot of the database and represents it in a single point of time.
    +5. Only supports single threaded
    +
    +
    +When using `_all_docs` API:
    +1. Supports parallel reads (using offset and range)
    +2. Using partitions may not represent the true snapshot of a database.  Some docs
    +   may be added or deleted in the database between loading data into different 
    +   Spark partitions.
    +
    +Performance of `_changes` API is still better in most cases (even with single threaded support). 
    +During several performance tests using 200 MB to 15 GB Cloudant databases, load time from Cloudant to Spark using 
    +`_changes` feed was faster to complete every time compared to `_all_docs`.
    --- End diff --
    
    I think it is good to qualify the circumstances under which `_changes` performs better than `_all_docs` but this seems to me a bit of a teaser. I think this probably isn't the place to provide a complete testing report so perhaps a slightly more summarized version.
    
    >Despite the restriction of single-threaded support the performance of the `_changes` API has been observed to be faster than `_all_docs` in testing with Cloudant databases up to 15 GB in size.
    
    ?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126802062
  
    --- Diff: sql-cloudant/src/main/scala/org/apache/bahir/cloudant/DefaultSource.scala ---
    @@ -98,29 +99,89 @@ class DefaultSource extends RelationProvider
     
           val config: CloudantConfig = JsonStoreConfigManager.getConfig(sqlContext, parameters)
     
    -      var allDocsDF: DataFrame = null
    +      var dataFrame: DataFrame = null
     
           val schema: StructType = {
             if (inSchema != null) {
               inSchema
    -        } else {
    -          val df = if (config.getSchemaSampleSize() ==
    -            JsonStoreConfigManager.ALL_DOCS_LIMIT &&
    +        } else if (!config.isInstanceOf[CloudantChangesConfig]
    +          || config.viewName != null || config.indexName != null) {
    +          val df = if (config.getSchemaSampleSize ==
    +            JsonStoreConfigManager.ALLDOCS_OR_CHANGES_LIMIT &&
                 config.viewName == null
                 && config.indexName == null) {
                 val cloudantRDD = new JsonStoreRDD(sqlContext.sparkContext, config)
    -            allDocsDF = sqlContext.read.json(cloudantRDD)
    -            allDocsDF
    +            dataFrame = sqlContext.read.json(cloudantRDD)
    +            dataFrame
               } else {
                 val dataAccess = new JsonStoreDataAccess(config)
                 val aRDD = sqlContext.sparkContext.parallelize(
    -                dataAccess.getMany(config.getSchemaSampleSize()))
    +                dataAccess.getMany(config.getSchemaSampleSize))
                 sqlContext.read.json(aRDD)
               }
               df.schema
    +        } else {
    +          /* Create a streaming context to handle transforming docs in
    +          * larger databases into Spark datasets
    +          */
    +          /* Allow the raw data and persisted RDDs to be accessible outside
    +          * of the streaming context.
    +          * See https://spark.apache.org/docs/latest/configuration.html
    +          * for more details.
    +          */
    +          sqlContext.sparkSession.conf.set("spark.streaming.unpersist", "false")
    +
    +          val ssc = new StreamingContext(sqlContext.sparkContext, Seconds(10))
    +          val streamingMap = {
    +            val selector = config.asInstanceOf[CloudantChangesConfig].getSelector
    +            if (selector != null) {
    +              Map(
    +                "database" -> config.getDbname,
    +                "selector" -> selector
    +              )
    +            } else {
    +              Map(
    +                "database" -> config.getDbname
    +              )
    +            }
    +          }
    +
    +          val changes = ssc.receiverStream(
    +            new CloudantReceiver(sqlContext.sparkContext.getConf, streamingMap))
    +          changes.persist(config.asInstanceOf[CloudantChangesConfig]
    +            .getStorageLevelForStreaming)
    +
    +          // Global RDD that's created from union of all RDDs
    +          var globalRDD = ssc.sparkContext.emptyRDD[String]
    +
    +          logger.info("Loading data from Cloudant using "
    +            + config.asInstanceOf[CloudantChangesConfig].getContinuousChangesUrl)
    +
    +          // Collect and union each RDD to convert all RDDs to a DataFrame
    +          changes.foreachRDD((rdd: RDD[String]) => {
    +            if (!rdd.isEmpty()) {
    +              if (globalRDD != null) {
    +                // Union RDDs in foreach loop
    +                globalRDD = globalRDD.union(rdd)
    +              } else {
    +                globalRDD = rdd
    +              }
    +            } else {
    +              // Convert final global RDD[String] to DataFrame
    +              dataFrame = sqlContext.sparkSession.read.json(globalRDD)
    +              ssc.stop(stopSparkContext = false, stopGracefully = false)
    +            }
    +          })
    +
    +          ssc.start
    +          // run streaming until all docs from continuous feed are received
    +          ssc.awaitTermination
    +          // ssc.stop(stopSparkContext = false, stopGracefully = false)
    --- End diff --
    
    Fixed in 5588c87.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [WIP] [BAHIR-110] Implement _changes API for non-streaming ...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    WIP: While running tests against databases with a size > 500 MB, `java.lang.OutOfMemoryError: Java heap space` error would occur (even when setting `--conf spark.driver.memory=10g`).  I believe this has to do with how the HTTP request is setup and called against the `_changes API` in [JsonStoreDataAccess.scala](https://github.com/apache/bahir/pull/45/files#diff-ab440bd537d48f7cf58cd9cf0ea143b1).
    Good news is I've created a test that uses Spark streaming (using CloudantReceiver.java) to read all docs from a Cloudant database into a Spark DataFrame.  It should work for a SQL Temp Table.  I ran this test without any java heap errors against a database size of 1 GB, 1.8 GB, and 14.2 GB.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    Build successful
     



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [WIP] [BAHIR-110] Implement _changes API for non-streaming ...

Posted by mayya-sharipova <gi...@git.apache.org>.
Github user mayya-sharipova commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    The `selector`  option doesn't work when  setting in config. For example, the below code will output all data:
    
    ```
    spark = SparkSession\
        .builder\
        .appName("Cloudant Spark SQL Example in Python using dataframes")\
        .config("cloudant.host", ACC)\
        .config("cloudant.username", USER)\
        .config("cloudant.password", PASS)\
        .config("cloudant.apiReceiver", "_changes")\
        .config("selector", "{\"Movie_year\": {\"$eq\": 2008}}")\
        .getOrCreate()
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    Build successful
     



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by mayya-sharipova <gi...@git.apache.org>.
Github user mayya-sharipova commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r125764983
  
    --- Diff: sql-cloudant/src/main/scala/org/apache/bahir/cloudant/CloudantChangesConfig.scala ---
    @@ -0,0 +1,108 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.bahir.cloudant
    +
    +import org.apache.bahir.cloudant.common.JsonStoreConfigManager
    +
    +class CloudantChangesConfig(protocol: String, host: String, dbName: String,
    +                            indexName: String = null, viewName: String = null)
    +                           (username: String, password: String, partitions: Int,
    +                            maxInPartition: Int, minInPartition: Int, requestTimeout: Long,
    +                            bulkSize: Int, schemaSampleSize: Int,
    +                            createDBOnSave: Boolean, apiReceiver: String, selector: String,
    +                            useQuery: Boolean, queryLimit: Int)
    +  extends CloudantConfig(protocol, host, dbName, indexName, viewName)(username, password,
    +    partitions, maxInPartition, minInPartition, requestTimeout, bulkSize, schemaSampleSize,
    +    createDBOnSave, apiReceiver, selector, useQuery, queryLimit) {
    +
    +  override val defaultIndex: String = apiReceiver
    +
    +  def getChangesUrl: String = {
    +    dbUrl + "/" + defaultIndex + "?include_docs=true&feed=normal"
    +  }
    +
    +  def getContinuousChangesUrl: String = {
    +    var url = dbUrl + "/" + defaultIndex + "?include_docs=true&feed=continuous&heartbeat=3000"
    +    if (selector != null) {
    +      url = url + "&filter=_selector"
    +    }
    +    url
    +  }
    +
    +  override def getTotalUrl(url: String): String = {
    +    if (url.contains('?')) {
    +      if (selector != null) {
    +        url + "&limit=1&filter=_selector"
    +      } else {
    +        url + "&limit=1"
    +      }
    +    } else {
    +      if (selector != null) {
    +        url + "?limit=1&filter=_selector"
    +      } else {
    +        url + "?limit=1"
    +      }
    +    }
    +  }
    +
    --- End diff --
    
    It not clear what `getLastUrl` function is used for


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [WIP] [BAHIR-110] Implement _changes API for non-streaming ...

Posted by mayya-sharipova <gi...@git.apache.org>.
Github user mayya-sharipova commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    The code using `option` parameters work as expected, and dbs are successfully loaded through `_changes`. But it seems to me that there could be better separation between classes `CloudantAllDocsConfig` and `CloudantChangesConfig`. Even though I am loading data using `_changes`, I have noticed there is still unnecessary calculations for the partitions going on. A part of it, is an extra unnecessary http request to calculate the number of `totalRows` in `JsonStoreRDD`: `https://ACCOUNT.cloudant.com/DB/_changes?limit=1&filter=_selector`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by mayya-sharipova <gi...@git.apache.org>.
Github user mayya-sharipova commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r125744695
  
    --- Diff: sql-cloudant/README.md ---
    @@ -52,39 +51,61 @@ Here each subsequent configuration overrides the previous one. Thus, configurati
     
     
     ### Configuration in application.conf
    -Default values are defined in [here](cloudant-spark-sql/src/main/resources/application.conf).
    +Default values are defined in [here](src/main/resources/application.conf).
     
     ### Configuration on SparkConf
     
     Name | Default | Meaning
     --- |:---:| ---
    +cloudant.apiReceiver|"_all_docs"| API endpoint for RelationProvider when loading or saving data from Cloudant to DataFrames or SQL temporary tables. Select between "_all_docs" or "_changes" endpoint.
     cloudant.protocol|https|protocol to use to transfer data: http or https
    -cloudant.host||cloudant host url
    -cloudant.username||cloudant userid
    -cloudant.password||cloudant password
    +cloudant.host| |cloudant host url
    +cloudant.username| |cloudant userid
    +cloudant.password| |cloudant password
     cloudant.useQuery|false|By default, _all_docs endpoint is used if configuration 'view' and 'index' (see below) are not set. When useQuery is enabled, _find endpoint will be used in place of _all_docs when query condition is not on primary key field (_id), so that query predicates may be driven into datastore. 
     cloudant.queryLimit|25|The maximum number of results returned when querying the _find endpoint.
     jsonstore.rdd.partitions|10|the number of partitions intent used to drive JsonStoreRDD loading query result in parallel. The actual number is calculated based on total rows returned and satisfying maxInPartition and minInPartition
     jsonstore.rdd.maxInPartition|-1|the max rows in a partition. -1 means unlimited
     jsonstore.rdd.minInPartition|10|the min rows in a partition.
     jsonstore.rdd.requestTimeout|900000| the request timeout in milliseconds
     bulkSize|200| the bulk save size
    -schemaSampleSize| "-1" | the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    -createDBOnSave|"false"| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +schemaSampleSize|-1| the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    +createDBOnSave|false| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +
    +The `cloudant.apiReceiver` option allows for _changes or _all_docs API endpoint to be called while loading Cloudant data into Spark DataFrames or SQL Tables,
    +or saving data from DataFrames or SQL Tables to a Cloudant database.  
    +
    +**Note:** When using `_changes` API, please consider: 
    +1. Results are partially ordered and may not be be presented in order in 
    +which documents were updated.
    +2. In case of shards' unavailability, you may see duplicate results (changes that have been seen already)
    +3. Can use `selector` option to retrieve all revisions for docs
    --- End diff --
    
    what do you mean by "all revisions" here?  I would say smth like this: " can use `selector` to filter docs to be loaded"


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    Build successful
     



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by mayya-sharipova <gi...@git.apache.org>.
Github user mayya-sharipova commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r125523804
  
    --- Diff: sql-cloudant/src/main/scala/org/apache/bahir/cloudant/CloudantAllDocsConfig.scala ---
    @@ -0,0 +1,67 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.bahir.cloudant
    +
    +import org.apache.bahir.cloudant.common.JsonStoreConfigManager
    +
    +class CloudantAllDocsConfig(protocol: String, host: String, dbName: String,
    +                            indexName: String = null, viewName: String = null)
    +                           (username: String, password: String, partitions: Int,
    +                            maxInPartition: Int, minInPartition: Int, requestTimeout: Long,
    +                            bulkSize: Int, schemaSampleSize: Int,
    +                            createDBOnSave: Boolean, apiReceiver: String, selector: String,
    --- End diff --
    
    lines seem to be > 80 characters long


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r128090121
  
    --- Diff: sql-cloudant/README.md ---
    @@ -52,39 +51,71 @@ Here each subsequent configuration overrides the previous one. Thus, configurati
     
     
     ### Configuration in application.conf
    -Default values are defined in [here](cloudant-spark-sql/src/main/resources/application.conf).
    +Default values are defined in [here](src/main/resources/application.conf).
     
     ### Configuration on SparkConf
     
     Name | Default | Meaning
     --- |:---:| ---
    +cloudant.apiReceiver|"_all_docs"| API endpoint for RelationProvider when loading or saving data from Cloudant to DataFrames or SQL temporary tables. Select between "_all_docs" or "_changes" endpoint.
     cloudant.protocol|https|protocol to use to transfer data: http or https
    -cloudant.host||cloudant host url
    -cloudant.username||cloudant userid
    -cloudant.password||cloudant password
    +cloudant.host| |cloudant host url
    +cloudant.username| |cloudant userid
    +cloudant.password| |cloudant password
     cloudant.useQuery|false|By default, _all_docs endpoint is used if configuration 'view' and 'index' (see below) are not set. When useQuery is enabled, _find endpoint will be used in place of _all_docs when query condition is not on primary key field (_id), so that query predicates may be driven into datastore. 
     cloudant.queryLimit|25|The maximum number of results returned when querying the _find endpoint.
     jsonstore.rdd.partitions|10|the number of partitions intent used to drive JsonStoreRDD loading query result in parallel. The actual number is calculated based on total rows returned and satisfying maxInPartition and minInPartition
     jsonstore.rdd.maxInPartition|-1|the max rows in a partition. -1 means unlimited
     jsonstore.rdd.minInPartition|10|the min rows in a partition.
     jsonstore.rdd.requestTimeout|900000| the request timeout in milliseconds
     bulkSize|200| the bulk save size
    -schemaSampleSize| "-1" | the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    -createDBOnSave|"false"| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +schemaSampleSize|-1| the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    +createDBOnSave|false| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +
    +The `cloudant.apiReceiver` option allows for _changes or _all_docs API endpoint to be called while loading Cloudant data into Spark DataFrames or SQL Tables,
    +or saving data from DataFrames or SQL Tables to a Cloudant database.
    +
    +**Note:** When using `_changes` API, please consider: 
    +1. Results are partially ordered and may not be be presented in order in 
    +which documents were updated.
    +2. In case of shards' unavailability, you may see duplicate results (changes that have been seen already)
    +3. Can use `selector` option to filter Cloudant docs during load
    +4. Supports a real snapshot of the database and represents it in a single point of time.
    +5. Only supports single threaded
    +
    +
    +When using `_all_docs` API:
    +1. Supports parallel reads (using offset and range)
    +2. Using partitions may not represent the true snapshot of a database.  Some docs
    +   may be added or deleted in the database between loading data into different 
    +   Spark partitions.
    +
    +Performance of `_changes` API is still better in most cases (even with single threaded support). 
    +During several performance tests using 200 MB to 15 GB Cloudant databases, load time from Cloudant to Spark using 
    +`_changes` feed was faster to complete every time compared to `_all_docs`.
    + 
    +See [CloudantChangesDFSuite](src/test/scala/org/apache/bahir/cloudant/CloudantChangesDFSuite.scala) 
    +for examples of loading data into a Spark DataFrame with `_changes` API.
     
     ### Configuration on Spark SQL Temporary Table or DataFrame
     
     Besides all the configurations passed to a temporary table or dataframe through SparkConf, it is also possible to set the following configurations in temporary table or dataframe using OPTIONS: 
     
     Name | Default | Meaning
     --- |:---:| ---
    -database||cloudant database name
    -view||cloudant view w/o the database name. only used for load.
    -index||cloudant search index w/o the database name. only used for load data with less than or equal to 200 results.
    -path||cloudant: as database name if database is not present
    -schemaSampleSize|"-1"| the sample size used to discover the schema for this temp table. -1 scans all documents
     bulkSize|200| the bulk save size
    -createDBOnSave|"false"| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +createDBOnSave|false| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +database| | Cloudant database name
    +index| | Cloudant search index w/o the database name. only used for load data with less than or equal to 200 results.
    --- End diff --
    
    @ricellis I removed the first part of the comment by accident.  The original comment was about `search` and that the limit value can be <= 200.  I don't see any limitations for `index` queries in the documentation.
    What if I change it to:
    `Cloudant Search index without the database name.  Search index queries are limited to returning 200 results so can only be used to load data with <= 200 results.`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [BAHIR-110] Implement _changes API for non-streaming...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r122797303
  
    --- Diff: sql-cloudant/src/test/scala/org/apache/bahir/cloudant/TestUtils.scala ---
    @@ -0,0 +1,73 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.bahir.cloudant
    +
    +import java.io.File
    +
    +object TestUtils {
    +  // List of test databases to create from JSON flat files
    +  val testDatabasesList: List[String] = List(
    +    "n_airportcodemapping",
    +    "n_booking",
    +    "n_customer",
    +    "n_customersession",
    +    "n_flight",
    +    "n_flight2",
    +    "n_flightsegment"
    +  )
    +
    +  // Set CouchDB/Cloudant host, username and password for local testing
    +  private val host = System.getenv("DB_HOST")
    --- End diff --
    
    Updated to `CLOUDANT_...` in 0256fc1.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [WIP] [BAHIR-110] Implement _changes API for non-streaming ...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    
    Refer to this link for build results (access rights to CI server needed): 
    http://169.45.79.58:8080/job/bahir_spark_pr_builder/75/



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    
    Refer to this link for build results (access rights to CI server needed): 
    http://169.45.79.58:8080/job/bahir_spark_pr_builder/90/



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [WIP] [BAHIR-110] Implement _changes API for non-streaming ...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    Build successful
     



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126990289
  
    --- Diff: sql-cloudant/src/test/scala/org/apache/bahir/cloudant/CloudantSparkSQLSuite.scala ---
    @@ -0,0 +1,101 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.bahir.cloudant
    +
    +import org.apache.spark.sql.{SparkSession, SQLContext, SQLImplicits}
    +
    +class CloudantSparkSQLSuite extends ClientSparkFunSuite {
    +  // import spark implicits
    +  private object testImplicits extends SQLImplicits {
    +    protected override def _sqlContext: SQLContext = spark.sqlContext
    +  }
    +
    +  import testImplicits._
    +
    +  val apiReceiver = "_all_docs"
    +
    +  override def beforeAll() {
    +    runIfTestsEnabled("Prepare Cloudant test databases") {
    +      super.beforeAll()
    +      spark = SparkSession.builder().config(conf)
    +        .config("cloudant.protocol", TestUtils.getProtocol)
    +        .config("cloudant.host", TestUtils.getHost)
    +        .config("cloudant.username", TestUtils.getUsername)
    +        .config("cloudant.password", TestUtils.getPassword)
    +        .config("cloudant.apiReceiver", apiReceiver)
    --- End diff --
    
    Fixed in 9f8bbc5.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    @yanglei99 Can you please review and add any comments?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [BAHIR-110] Implement _changes API for non-streaming...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r122794148
  
    --- Diff: sql-cloudant/src/test/scala/org/apache/bahir/cloudant/TestUtils.scala ---
    @@ -0,0 +1,73 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.bahir.cloudant
    +
    +import java.io.File
    +
    +object TestUtils {
    +  // List of test databases to create from JSON flat files
    +  val testDatabasesList: List[String] = List(
    +    "n_airportcodemapping",
    +    "n_booking",
    +    "n_customer",
    +    "n_customersession",
    +    "n_flight",
    +    "n_flight2",
    +    "n_flightsegment"
    +  )
    +
    +  // Set CouchDB/Cloudant host, username and password for local testing
    +  private val host = System.getenv("DB_HOST")
    --- End diff --
    
    @ckadner I can do that or I can do `CLOUDANT_HOST`.  Eventually I'd like to have `COUCHDB_HOST` as well.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [WIP] [BAHIR-110] Implement _changes API for non-streaming ...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    
    Refer to this link for build results (access rights to CI server needed): 
    http://169.45.79.58:8080/job/bahir_spark_pr_builder/74/



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    
    Refer to this link for build results (access rights to CI server needed): 
    http://169.45.79.58:8080/job/bahir_spark_pr_builder/87/



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    Can one of the admins verify this patch?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by ricellis <gi...@git.apache.org>.
Github user ricellis commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126401728
  
    --- Diff: sql-cloudant/README.md ---
    @@ -31,15 +31,14 @@ The `--packages` argument can also be used with `bin/spark-submit`.
     
     Submit a job in Python:
         
    -    spark-submit  --master local[4] --jars <path to cloudant-spark.jar>  <path to python script> 
    +    spark-submit  --master local[4] --packages org.apache.bahir:spark-sql-cloudant_2.11:2.2.0-SNAPSHOT  <path to python script> 
         
     Submit a job in Scala:
     
    -	spark-submit --class "<your class>" --master local[4] --jars <path to cloudant-spark.jar> <path to your app jar>
    +	spark-submit --class "<your class>" --master local[4] --packages org.apache.bahir:spark-sql-cloudant_2.11:2.2.0-SNAPSHOT <path to spark-sql-cloudant jar>
    --- End diff --
    
    `SNAPSHOT` again?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by mayya-sharipova <gi...@git.apache.org>.
Github user mayya-sharipova commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    @emlaver 
    I am getting the following unexpected behaviour:
    I have a database with 13 docs and 1 deleted doc. When displaying `df.count`, I am getting `14` which is incorrect.  When displaying a dataframe, I am getting the last record is NULL.
    +--------+---+--------------------+-----------+
    |_deleted|_id|                _rev|airportName|
    +--------+---+--------------------+-----------+
    |    null|DEL|1-67f14f8891a9f32...|      Delhi|
    |    null|JFK|1-ee8206c8e56a114...|   New York|
    |    null|SVO|1-7d18769b68f6099...|     Moscow|
    |    null|FRA|1-f358b62b0499340...|  Frankfurt|
    |    null|HKG|1-b040e40df5d0080...|  Hong Kong|
    |    null|CDG|1-8c51e401185272e...|      Paris|
    |    null|FCO|1-89431c8db8aa8e4...|       Rome|
    |    null|NRT|1-dce312ac1414110...|      Tokyo|
    |    null|LHR|1-303c622ad8380c9...|     London|
    |    null|BOM|2-a3f39a0741938c4...|    Mumbaii|
    |    null|YUL|1-19a9fe9cace23ec...|   Montreal|
    |    null|IKA|1-3dea74452ca86af...|     Tehran|
    |    null|SIN|1-67037272289432e...|  Singapore|
    |    true|SYD|2-1cc4f2c62db144a...|       null|
    +--------+---+--------------------+-----------+
    
    We should NOT load into dataframe any deleted documents. A user may have thousands or millions of deleted documents. We should load only undeleted docs, and a dataframe should NOT have a column `"_deleted"`.
    
    ________
    Another error:
    Occasionally, when running `CloudantDF.py` example, get an error:
    File "/Cloudant/bahir/sql-cloudant/examples/python/CloudantDF.py", line 45, in <module>
        df.filter(df.airportName >= 'Moscow').select("_id",'airportName').show()
      File "..spark-2.2.0-bin-hadoop2.7/python/lib/pyspark.zip/pyspark/sql/dataframe.py", line 1020, in __getattr__
    AttributeError: 'DataFrame' object has no attribute 'airportName' 
    
    For this PR, we can disregard this error and investigate further in following PRs.
    _____________
    
    
    
    



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126073211
  
    --- Diff: sql-cloudant/src/main/scala/org/apache/bahir/cloudant/CloudantChangesConfig.scala ---
    @@ -0,0 +1,108 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.bahir.cloudant
    +
    +import org.apache.bahir.cloudant.common.JsonStoreConfigManager
    +
    +class CloudantChangesConfig(protocol: String, host: String, dbName: String,
    +                            indexName: String = null, viewName: String = null)
    +                           (username: String, password: String, partitions: Int,
    +                            maxInPartition: Int, minInPartition: Int, requestTimeout: Long,
    +                            bulkSize: Int, schemaSampleSize: Int,
    +                            createDBOnSave: Boolean, apiReceiver: String, selector: String,
    +                            useQuery: Boolean, queryLimit: Int)
    +  extends CloudantConfig(protocol, host, dbName, indexName, viewName)(username, password,
    +    partitions, maxInPartition, minInPartition, requestTimeout, bulkSize, schemaSampleSize,
    +    createDBOnSave, apiReceiver, selector, useQuery, queryLimit) {
    +
    +  override val defaultIndex: String = apiReceiver
    +
    +  def getChangesUrl: String = {
    +    dbUrl + "/" + defaultIndex + "?include_docs=true&feed=normal"
    +  }
    +
    +  def getContinuousChangesUrl: String = {
    +    var url = dbUrl + "/" + defaultIndex + "?include_docs=true&feed=continuous&heartbeat=3000"
    +    if (selector != null) {
    +      url = url + "&filter=_selector"
    +    }
    +    url
    +  }
    +
    +  override def getTotalUrl(url: String): String = {
    +    if (url.contains('?')) {
    +      if (selector != null) {
    +        url + "&limit=1&filter=_selector"
    +      } else {
    +        url + "&limit=1"
    +      }
    +    } else {
    +      if (selector != null) {
    +        url + "?limit=1&filter=_selector"
    +      } else {
    +        url + "?limit=1"
    +      }
    +    }
    +  }
    +
    --- End diff --
    
    Removed in 47064b7.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    Build successful
     



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    
    Refer to this link for build results (access rights to CI server needed): 
    http://169.45.79.58:8080/job/bahir_spark_pr_builder/80/



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    @mayya-sharipova Thank you for all the time you've spent reviewing this work.
    The storageLevel option was not working as expected and also was not in the correct section in the README.  I’ve renamed the option to `cloudant.storageLevel` (as this option only works when _changes endpoint option is set), updated the README, and successfully tested and verified that the option is working using spark-submit and SparkSession’s config in 052abb4.  I've run the Scala tests and examples and they all passed.  Could you please review and approve these changes?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by mayya-sharipova <gi...@git.apache.org>.
Github user mayya-sharipova commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r125523606
  
    --- Diff: sql-cloudant/README.md ---
    @@ -52,39 +51,61 @@ Here each subsequent configuration overrides the previous one. Thus, configurati
     
     
     ### Configuration in application.conf
    -Default values are defined in [here](cloudant-spark-sql/src/main/resources/application.conf).
    +Default values are defined in [here](src/main/resources/application.conf).
     
     ### Configuration on SparkConf
     
     Name | Default | Meaning
     --- |:---:| ---
    +cloudant.apiReceiver|"_all_docs"| API endpoint for RelationProvider when loading or saving data from Cloudant to DataFrames or SQL temporary tables. Select between "_all_docs" or "_changes" endpoint.
     cloudant.protocol|https|protocol to use to transfer data: http or https
    -cloudant.host||cloudant host url
    -cloudant.username||cloudant userid
    -cloudant.password||cloudant password
    +cloudant.host| |cloudant host url
    +cloudant.username| |cloudant userid
    +cloudant.password| |cloudant password
     cloudant.useQuery|false|By default, _all_docs endpoint is used if configuration 'view' and 'index' (see below) are not set. When useQuery is enabled, _find endpoint will be used in place of _all_docs when query condition is not on primary key field (_id), so that query predicates may be driven into datastore. 
     cloudant.queryLimit|25|The maximum number of results returned when querying the _find endpoint.
     jsonstore.rdd.partitions|10|the number of partitions intent used to drive JsonStoreRDD loading query result in parallel. The actual number is calculated based on total rows returned and satisfying maxInPartition and minInPartition
     jsonstore.rdd.maxInPartition|-1|the max rows in a partition. -1 means unlimited
     jsonstore.rdd.minInPartition|10|the min rows in a partition.
     jsonstore.rdd.requestTimeout|900000| the request timeout in milliseconds
     bulkSize|200| the bulk save size
    -schemaSampleSize| "-1" | the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    -createDBOnSave|"false"| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +schemaSampleSize|-1| the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    +createDBOnSave|false| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +
    +The `cloudant.apiReceiver` option allows for _changes or _all_docs API endpoint to be called while loading Cloudant data into Spark DataFrames or SQL Tables,
    +or saving data from DataFrames or SQL Tables to a Cloudant database.  
    +
    +**Note:** When using `_changes` API, please consider: 
    +1. Results are partially ordered and may not be be presented in order in 
    +which documents were updated.
    +2. In case of shards' unavailability, you may see duplicate results (changes that have been seen already)
    +3. Can use `selector` option to retrieve all revisions for docs
    +4. Only supports single threaded
    +
    +When using `_all_docs` API:
    +1. Supports parallel reads (using offset and range)
    +
    +Performance of `_changes` API is still better in most cases (even with single threaded support). 
    +During several performance tests using 50 to 200 MB Cloudant databases, load time from Cloudant to Spark using `_changes` 
    +feed was faster to complete every time compared to `_all_docs`.
    + 
    --- End diff --
    
    with `_changes`, you can specify `selector` option using CQ format, thus significantly limit the number of documents to be loaded into Spark.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126444627
  
    --- Diff: sql-cloudant/README.md ---
    @@ -31,15 +31,14 @@ The `--packages` argument can also be used with `bin/spark-submit`.
     
     Submit a job in Python:
         
    -    spark-submit  --master local[4] --jars <path to cloudant-spark.jar>  <path to python script> 
    +    spark-submit  --master local[4] --packages org.apache.bahir:spark-sql-cloudant_2.11:2.2.0-SNAPSHOT  <path to python script> 
    --- End diff --
    
    Good point, this should probably be something like `--packages org.apache.bahir:spark-sql-cloudant_SCALA_VERSION:PACKAGE_VERSION`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    @lresende Environment variables for testing on Jenkins:
    DB_HOST
    DB_USER
    DB_PASSWORD
    DB_PROTOCOL (not required if using https)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126801991
  
    --- Diff: sql-cloudant/README.md ---
    @@ -52,39 +51,71 @@ Here each subsequent configuration overrides the previous one. Thus, configurati
     
     
     ### Configuration in application.conf
    -Default values are defined in [here](cloudant-spark-sql/src/main/resources/application.conf).
    +Default values are defined in [here](src/main/resources/application.conf).
     
     ### Configuration on SparkConf
     
     Name | Default | Meaning
     --- |:---:| ---
    +cloudant.apiReceiver|"_all_docs"| API endpoint for RelationProvider when loading or saving data from Cloudant to DataFrames or SQL temporary tables. Select between "_all_docs" or "_changes" endpoint.
     cloudant.protocol|https|protocol to use to transfer data: http or https
    -cloudant.host||cloudant host url
    -cloudant.username||cloudant userid
    -cloudant.password||cloudant password
    +cloudant.host| |cloudant host url
    +cloudant.username| |cloudant userid
    +cloudant.password| |cloudant password
     cloudant.useQuery|false|By default, _all_docs endpoint is used if configuration 'view' and 'index' (see below) are not set. When useQuery is enabled, _find endpoint will be used in place of _all_docs when query condition is not on primary key field (_id), so that query predicates may be driven into datastore. 
     cloudant.queryLimit|25|The maximum number of results returned when querying the _find endpoint.
     jsonstore.rdd.partitions|10|the number of partitions intent used to drive JsonStoreRDD loading query result in parallel. The actual number is calculated based on total rows returned and satisfying maxInPartition and minInPartition
     jsonstore.rdd.maxInPartition|-1|the max rows in a partition. -1 means unlimited
     jsonstore.rdd.minInPartition|10|the min rows in a partition.
     jsonstore.rdd.requestTimeout|900000| the request timeout in milliseconds
     bulkSize|200| the bulk save size
    -schemaSampleSize| "-1" | the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    -createDBOnSave|"false"| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +schemaSampleSize|-1| the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    +createDBOnSave|false| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +
    +The `cloudant.apiReceiver` option allows for _changes or _all_docs API endpoint to be called while loading Cloudant data into Spark DataFrames or SQL Tables,
    +or saving data from DataFrames or SQL Tables to a Cloudant database.
    +
    +**Note:** When using `_changes` API, please consider: 
    +1. Results are partially ordered and may not be be presented in order in 
    +which documents were updated.
    +2. In case of shards' unavailability, you may see duplicate results (changes that have been seen already)
    +3. Can use `selector` option to filter Cloudant docs during load
    +4. Supports a real snapshot of the database and represents it in a single point of time.
    +5. Only supports single threaded
    +
    +
    +When using `_all_docs` API:
    +1. Supports parallel reads (using offset and range)
    +2. Using partitions may not represent the true snapshot of a database.  Some docs
    +   may be added or deleted in the database between loading data into different 
    +   Spark partitions.
    +
    +Performance of `_changes` API is still better in most cases (even with single threaded support). 
    +During several performance tests using 200 MB to 15 GB Cloudant databases, load time from Cloudant to Spark using 
    +`_changes` feed was faster to complete every time compared to `_all_docs`.
    --- End diff --
    
    After our Slack discussion and @yanglei99 comments by e-mail, I've removed this in 5588c87.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by mayya-sharipova <gi...@git.apache.org>.
Github user mayya-sharipova commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126151630
  
    --- Diff: sql-cloudant/README.md ---
    @@ -52,39 +51,71 @@ Here each subsequent configuration overrides the previous one. Thus, configurati
     
     
     ### Configuration in application.conf
    -Default values are defined in [here](cloudant-spark-sql/src/main/resources/application.conf).
    +Default values are defined in [here](src/main/resources/application.conf).
     
     ### Configuration on SparkConf
     
     Name | Default | Meaning
     --- |:---:| ---
    +cloudant.apiReceiver|"_all_docs"| API endpoint for RelationProvider when loading or saving data from Cloudant to DataFrames or SQL temporary tables. Select between "_all_docs" or "_changes" endpoint.
     cloudant.protocol|https|protocol to use to transfer data: http or https
    -cloudant.host||cloudant host url
    -cloudant.username||cloudant userid
    -cloudant.password||cloudant password
    +cloudant.host| |cloudant host url
    +cloudant.username| |cloudant userid
    +cloudant.password| |cloudant password
     cloudant.useQuery|false|By default, _all_docs endpoint is used if configuration 'view' and 'index' (see below) are not set. When useQuery is enabled, _find endpoint will be used in place of _all_docs when query condition is not on primary key field (_id), so that query predicates may be driven into datastore. 
     cloudant.queryLimit|25|The maximum number of results returned when querying the _find endpoint.
     jsonstore.rdd.partitions|10|the number of partitions intent used to drive JsonStoreRDD loading query result in parallel. The actual number is calculated based on total rows returned and satisfying maxInPartition and minInPartition
     jsonstore.rdd.maxInPartition|-1|the max rows in a partition. -1 means unlimited
     jsonstore.rdd.minInPartition|10|the min rows in a partition.
     jsonstore.rdd.requestTimeout|900000| the request timeout in milliseconds
     bulkSize|200| the bulk save size
    -schemaSampleSize| "-1" | the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    -createDBOnSave|"false"| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +schemaSampleSize|-1| the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    +createDBOnSave|false| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +
    +The `cloudant.apiReceiver` option allows for _changes or _all_docs API endpoint to be called while loading Cloudant data into Spark DataFrames or SQL Tables,
    +or saving data from DataFrames or SQL Tables to a Cloudant database.
    +
    +**Note:** When using `_changes` API, please consider: 
    +1. Results are partially ordered and may not be be presented in order in 
    +which documents were updated.
    +2. In case of shards' unavailability, you may see duplicate results (changes that have been seen already)
    +3. Can use `selector` option to filter Cloudant docs during load
    +4. Supports a real snapshot of the database and represents it in a single point of time.
    +5. Only supports single threaded
    +
    +
    +When using `_all_docs` API:
    +1. Supports parallel reads (using offset and range)
    +2. Using partitions may not represent the true snapshot of a database.  Some docs
    +   may be added or deleted in the database between loading data into different 
    +   Spark partitions.
    +
    +Performance of `_changes` API is still better in most cases (even with single threaded support). 
    +During several performance tests using 200 MB to 15 GB Cloudant databases, load time from Cloudant to Spark using 
    +`_changes` feed was faster to complete every time compared to `_all_docs`.
    + 
    +See [CloudantChangesDFSuite](src/test/scala/org/apache/bahir/cloudant/CloudantChangesDFSuite.scala) 
    +for examples of loading data into a Spark DataFrame with `_changes` API.
     
     ### Configuration on Spark SQL Temporary Table or DataFrame
     
     Besides all the configurations passed to a temporary table or dataframe through SparkConf, it is also possible to set the following configurations in temporary table or dataframe using OPTIONS: 
     
     Name | Default | Meaning
     --- |:---:| ---
    -database||cloudant database name
    -view||cloudant view w/o the database name. only used for load.
    -index||cloudant search index w/o the database name. only used for load data with less than or equal to 200 results.
    -path||cloudant: as database name if database is not present
    -schemaSampleSize|"-1"| the sample size used to discover the schema for this temp table. -1 scans all documents
     bulkSize|200| the bulk save size
    -createDBOnSave|"false"| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +createDBOnSave|false| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +database| | Cloudant database name
    +index| | Cloudant search index w/o the database name. only used for load data with less than or equal to 200 results.
    +path| | Cloudant: as database name if database is not present
    +schemaSampleSize|-1| the sample size used to discover the schema for this temp table. -1 scans all documents
    +selector|all documents| a selector written in Cloudant Query syntax, specifying conditions for selecting documents when the `cloudant.apiReceiver` option is set to `_changes`. Only documents satisfying the selector's conditions will be retrieved from Cloudant and loaded into Spark.
    +storageLevel|MEMORY_ONLY_SER| the storage level when persisting Spark data sets during load when `cloudant.apiReceiver` option equals `_changes`
    --- End diff --
    
    We should also state here other options, or at least provide a link to other options.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126802018
  
    --- Diff: sql-cloudant/README.md ---
    @@ -52,39 +51,71 @@ Here each subsequent configuration overrides the previous one. Thus, configurati
     
     
     ### Configuration in application.conf
    -Default values are defined in [here](cloudant-spark-sql/src/main/resources/application.conf).
    +Default values are defined in [here](src/main/resources/application.conf).
     
     ### Configuration on SparkConf
     
     Name | Default | Meaning
     --- |:---:| ---
    +cloudant.apiReceiver|"_all_docs"| API endpoint for RelationProvider when loading or saving data from Cloudant to DataFrames or SQL temporary tables. Select between "_all_docs" or "_changes" endpoint.
     cloudant.protocol|https|protocol to use to transfer data: http or https
    -cloudant.host||cloudant host url
    -cloudant.username||cloudant userid
    -cloudant.password||cloudant password
    +cloudant.host| |cloudant host url
    +cloudant.username| |cloudant userid
    +cloudant.password| |cloudant password
     cloudant.useQuery|false|By default, _all_docs endpoint is used if configuration 'view' and 'index' (see below) are not set. When useQuery is enabled, _find endpoint will be used in place of _all_docs when query condition is not on primary key field (_id), so that query predicates may be driven into datastore. 
     cloudant.queryLimit|25|The maximum number of results returned when querying the _find endpoint.
     jsonstore.rdd.partitions|10|the number of partitions intent used to drive JsonStoreRDD loading query result in parallel. The actual number is calculated based on total rows returned and satisfying maxInPartition and minInPartition
     jsonstore.rdd.maxInPartition|-1|the max rows in a partition. -1 means unlimited
     jsonstore.rdd.minInPartition|10|the min rows in a partition.
     jsonstore.rdd.requestTimeout|900000| the request timeout in milliseconds
     bulkSize|200| the bulk save size
    -schemaSampleSize| "-1" | the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    -createDBOnSave|"false"| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +schemaSampleSize|-1| the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    +createDBOnSave|false| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +
    +The `cloudant.apiReceiver` option allows for _changes or _all_docs API endpoint to be called while loading Cloudant data into Spark DataFrames or SQL Tables,
    +or saving data from DataFrames or SQL Tables to a Cloudant database.
    +
    +**Note:** When using `_changes` API, please consider: 
    +1. Results are partially ordered and may not be be presented in order in 
    +which documents were updated.
    +2. In case of shards' unavailability, you may see duplicate results (changes that have been seen already)
    +3. Can use `selector` option to filter Cloudant docs during load
    +4. Supports a real snapshot of the database and represents it in a single point of time.
    +5. Only supports single threaded
    +
    +
    +When using `_all_docs` API:
    +1. Supports parallel reads (using offset and range)
    +2. Using partitions may not represent the true snapshot of a database.  Some docs
    +   may be added or deleted in the database between loading data into different 
    +   Spark partitions.
    +
    +Performance of `_changes` API is still better in most cases (even with single threaded support). 
    +During several performance tests using 200 MB to 15 GB Cloudant databases, load time from Cloudant to Spark using 
    +`_changes` feed was faster to complete every time compared to `_all_docs`.
    + 
    +See [CloudantChangesDFSuite](src/test/scala/org/apache/bahir/cloudant/CloudantChangesDFSuite.scala) 
    +for examples of loading data into a Spark DataFrame with `_changes` API.
     
     ### Configuration on Spark SQL Temporary Table or DataFrame
     
     Besides all the configurations passed to a temporary table or dataframe through SparkConf, it is also possible to set the following configurations in temporary table or dataframe using OPTIONS: 
     
     Name | Default | Meaning
     --- |:---:| ---
    -database||cloudant database name
    -view||cloudant view w/o the database name. only used for load.
    -index||cloudant search index w/o the database name. only used for load data with less than or equal to 200 results.
    -path||cloudant: as database name if database is not present
    -schemaSampleSize|"-1"| the sample size used to discover the schema for this temp table. -1 scans all documents
     bulkSize|200| the bulk save size
    -createDBOnSave|"false"| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +createDBOnSave|false| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +database| | Cloudant database name
    +index| | Cloudant search index w/o the database name. only used for load data with less than or equal to 200 results.
    --- End diff --
    
    Fixed in 5588c87.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [BAHIR-110] Implement _changes API for non-streaming...

Posted by mayya-sharipova <gi...@git.apache.org>.
Github user mayya-sharipova commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r128830778
  
    --- Diff: sql-cloudant/src/main/scala/org/apache/bahir/cloudant/internal/ChangesReceiver.scala ---
    @@ -0,0 +1,100 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.bahir.cloudant.internal
    +
    +import org.slf4j.{Logger, LoggerFactory}
    +import play.api.libs.json.Json
    +import scalaj.http._
    +
    +import org.apache.spark.SparkConf
    +import org.apache.spark.storage.StorageLevel
    +import org.apache.spark.streaming.receiver.Receiver
    +
    +import org.apache.bahir.cloudant.CloudantChangesConfig
    +import org.apache.bahir.cloudant.common._
    +
    +
    +class ChangesReceiver(config: CloudantChangesConfig)
    +  extends Receiver[String](StorageLevel.MEMORY_AND_DISK) {
    +
    +  def onStart() {
    +    // Start the thread that receives data over a connection
    +    new Thread("Cloudant Receiver") {
    +      override def run() { receive() }
    +    }.start()
    +  }
    +
    +  private def receive(): Unit = {
    +    // Get total number of docs in database using _all_docs endpoint
    +    val limit = new JsonStoreDataAccess(config)
    +      .getTotalRows(config.getTotalUrl, queryUsed = false)
    +
    +    // Get continuous _changes url
    +    val url = config.getChangesReceiverUrl.toString
    +    val selector: String = {
    +      "{\"selector\":" + config.getSelector + "}"
    +    }
    +
    +    var count = 0
    +    val clRequest: HttpRequest = config.username match {
    +      case null =>
    +        Http(url)
    +          .postData(selector)
    +          .timeout(connTimeoutMs = 1000, readTimeoutMs = 0)
    +          .header("Content-Type", "application/json")
    +          .header("User-Agent", "spark-cloudant")
    +      case _ =>
    +        Http(url)
    +          .postData(selector)
    +          .timeout(connTimeoutMs = 1000, readTimeoutMs = 0)
    +          .header("Content-Type", "application/json")
    +          .header("User-Agent", "spark-cloudant")
    +          .auth(config.username, config.password)
    +    }
    +
    +    clRequest.exec((code, headers, is) => {
    +      if (code == 200) {
    +        scala.io.Source.fromInputStream(is, "utf-8").getLines().foreach(line => {
    +          if (line.length() > 0) {
    +            val json = Json.parse(line)
    +            val jsonDoc = (json \ "doc").getOrElse(null)
    +            var doc = ""
    +            if(jsonDoc != null) {
    +              doc = Json.stringify(jsonDoc)
    +              // Verify that doc is not empty and is not deleted
    +              val deleted = (jsonDoc \ "_deleted").getOrElse(null)
    +              if(!doc.isEmpty && deleted == null) {
    +                store(doc)
    +                count += 1
    +              }
    +            }
    +          } else if (count >= limit) {
    --- End diff --
    
    should we check `(count >= limit)` before line 72 for all objects, not only empty ones?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [WIP] [BAHIR-110] Implement _changes API for non-streaming ...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    
    Refer to this link for build results (access rights to CI server needed): 
    http://169.45.79.58:8080/job/bahir_spark_pr_builder/76/



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    
    Refer to this link for build results (access rights to CI server needed): 
    http://169.45.79.58:8080/job/bahir_spark_pr_builder/78/



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126753981
  
    --- Diff: sql-cloudant/src/main/scala/org/apache/bahir/cloudant/CloudantReceiver.scala ---
    @@ -16,23 +16,20 @@
      */
     package org.apache.bahir.cloudant
     
    -// scalastyle:off
    -import scalaj.http._
    -
     import play.api.libs.json.Json
    +import scalaj.http._
     
    +import org.apache.spark.SparkConf
     import org.apache.spark.storage.StorageLevel
     import org.apache.spark.streaming.receiver.Receiver
    -import org.apache.spark.SparkConf
     
     import org.apache.bahir.cloudant.common._
    -// scalastyle:on
     
     class CloudantReceiver(sparkConf: SparkConf, cloudantParams: Map[String, String])
         extends Receiver[String](StorageLevel.MEMORY_AND_DISK) {
    -  lazy val config: CloudantConfig = {
    +  lazy val config: CloudantChangesConfig = {
    --- End diff --
    
    From our conversation over Slack, let's not change the name of the `CloudantReceiver` class.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126445660
  
    --- Diff: sql-cloudant/src/main/scala/org/apache/bahir/cloudant/CloudantChangesConfig.scala ---
    @@ -0,0 +1,64 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.bahir.cloudant
    +
    +import org.apache.spark.storage.StorageLevel
    +
    +class CloudantChangesConfig(protocol: String, host: String, dbName: String,
    +                            indexName: String = null, viewName: String = null)
    +                           (username: String, password: String, partitions: Int,
    +                            maxInPartition: Int, minInPartition: Int, requestTimeout: Long,
    +                            bulkSize: Int, schemaSampleSize: Int,
    +                            createDBOnSave: Boolean, apiReceiver: String, selector: String,
    +                            storageLevel: StorageLevel, useQuery: Boolean, queryLimit: Int)
    +  extends CloudantConfig(protocol, host, dbName, indexName, viewName)(username, password,
    +    partitions, maxInPartition, minInPartition, requestTimeout, bulkSize, schemaSampleSize,
    +    createDBOnSave, apiReceiver, useQuery, queryLimit) {
    +
    +  override val defaultIndex: String = apiReceiver
    +
    +  def getSelector : String = {
    +    if (selector != null && !selector.isEmpty) {
    +      selector
    +    } else {
    +      // Exclude design docs
    +      "{ \"_id\": { \"$regex\": \"^(?!.*_design/)\" } }"
    --- End diff --
    
    I don't think it needs the `.*`.  It's probably worth having adding a test case to verify this.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    
    Refer to this link for build results (access rights to CI server needed): 
    http://169.45.79.58:8080/job/bahir_spark_pr_builder/79/



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    Build failed, see build log for details
     



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [WIP] [BAHIR-110] Implement _changes API for non-streaming ...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    Build successful
     



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [WIP] [BAHIR-110] Implement _changes API for non-streaming ...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    Build successful
     



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [BAHIR-110] Implement _changes API for non-streaming...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/bahir/pull/45


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by ricellis <gi...@git.apache.org>.
Github user ricellis commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126423468
  
    --- Diff: sql-cloudant/src/main/scala/org/apache/bahir/cloudant/CloudantChangesConfig.scala ---
    @@ -0,0 +1,64 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.bahir.cloudant
    +
    +import org.apache.spark.storage.StorageLevel
    +
    +class CloudantChangesConfig(protocol: String, host: String, dbName: String,
    +                            indexName: String = null, viewName: String = null)
    +                           (username: String, password: String, partitions: Int,
    +                            maxInPartition: Int, minInPartition: Int, requestTimeout: Long,
    +                            bulkSize: Int, schemaSampleSize: Int,
    +                            createDBOnSave: Boolean, apiReceiver: String, selector: String,
    +                            storageLevel: StorageLevel, useQuery: Boolean, queryLimit: Int)
    +  extends CloudantConfig(protocol, host, dbName, indexName, viewName)(username, password,
    +    partitions, maxInPartition, minInPartition, requestTimeout, bulkSize, schemaSampleSize,
    +    createDBOnSave, apiReceiver, useQuery, queryLimit) {
    +
    +  override val defaultIndex: String = apiReceiver
    +
    +  def getSelector : String = {
    +    if (selector != null && !selector.isEmpty) {
    +      selector
    +    } else {
    +      // Exclude design docs
    +      "{ \"_id\": { \"$regex\": \"^(?!.*_design/)\" } }"
    --- End diff --
    
    Does this regex really need a `.*`? Doesn't it make it exclude a document with a name like `my_design`? I guess the trailing slash protects against that because the `/` will appear in a design doc, but not a normal doc, but someone could create a doc with `/` I'm not sure if it would be encoded at the point of the regex check. Maybe more straightforward just to have `^(?!_design/)`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [WIP] [BAHIR-110] Implement _changes API for non-streaming ...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    Build successful
     



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [WIP] [BAHIR-110] Implement _changes API for non-streaming ...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    
    Refer to this link for build results (access rights to CI server needed): 
    http://169.45.79.58:8080/job/bahir_spark_pr_builder/77/



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    
    Refer to this link for build results (access rights to CI server needed): 
    http://169.45.79.58:8080/job/bahir_spark_pr_builder/88/



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    
    Refer to this link for build results (access rights to CI server needed): 
    http://169.45.79.58:8080/job/bahir_spark_pr_builder/86/



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    
    Refer to this link for build results (access rights to CI server needed): 
    http://169.45.79.58:8080/job/bahir_spark_pr_builder/65/



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by ricellis <gi...@git.apache.org>.
Github user ricellis commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126402346
  
    --- Diff: sql-cloudant/README.md ---
    @@ -52,39 +51,71 @@ Here each subsequent configuration overrides the previous one. Thus, configurati
     
     
     ### Configuration in application.conf
    -Default values are defined in [here](cloudant-spark-sql/src/main/resources/application.conf).
    +Default values are defined in [here](src/main/resources/application.conf).
     
     ### Configuration on SparkConf
     
     Name | Default | Meaning
     --- |:---:| ---
    +cloudant.apiReceiver|"_all_docs"| API endpoint for RelationProvider when loading or saving data from Cloudant to DataFrames or SQL temporary tables. Select between "_all_docs" or "_changes" endpoint.
    --- End diff --
    
    I would say
    >Cloudant API endpoint to use for
    
    or
    >Select between the Cloudant `_all_docs` or `_changes` endpoint
    
    Probably also worth a "see below for details|notes|further explanation" or similar to help people find the content that would help them choose the appropriate endpoint.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    Build successful
     



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by mayya-sharipova <gi...@git.apache.org>.
Github user mayya-sharipova commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126954747
  
    --- Diff: sql-cloudant/src/test/scala/org/apache/bahir/cloudant/CloudantSparkSQLSuite.scala ---
    @@ -0,0 +1,101 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.bahir.cloudant
    +
    +import org.apache.spark.sql.{SparkSession, SQLContext, SQLImplicits}
    +
    +class CloudantSparkSQLSuite extends ClientSparkFunSuite {
    +  // import spark implicits
    +  private object testImplicits extends SQLImplicits {
    +    protected override def _sqlContext: SQLContext = spark.sqlContext
    +  }
    +
    +  import testImplicits._
    +
    +  val apiReceiver = "_all_docs"
    +
    +  override def beforeAll() {
    +    runIfTestsEnabled("Prepare Cloudant test databases") {
    +      super.beforeAll()
    +      spark = SparkSession.builder().config(conf)
    +        .config("cloudant.protocol", TestUtils.getProtocol)
    +        .config("cloudant.host", TestUtils.getHost)
    +        .config("cloudant.username", TestUtils.getUsername)
    +        .config("cloudant.password", TestUtils.getPassword)
    +        .config("cloudant.apiReceiver", apiReceiver)
    --- End diff --
    
    @emlaver is it `apiReceiver` or `endpoint`?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126801183
  
    --- Diff: sql-cloudant/README.md ---
    @@ -52,39 +51,71 @@ Here each subsequent configuration overrides the previous one. Thus, configurati
     
     
     ### Configuration in application.conf
    -Default values are defined in [here](cloudant-spark-sql/src/main/resources/application.conf).
    +Default values are defined in [here](src/main/resources/application.conf).
     
     ### Configuration on SparkConf
     
     Name | Default | Meaning
     --- |:---:| ---
    +cloudant.apiReceiver|"_all_docs"| API endpoint for RelationProvider when loading or saving data from Cloudant to DataFrames or SQL temporary tables. Select between "_all_docs" or "_changes" endpoint.
     cloudant.protocol|https|protocol to use to transfer data: http or https
    -cloudant.host||cloudant host url
    -cloudant.username||cloudant userid
    -cloudant.password||cloudant password
    +cloudant.host| |cloudant host url
    +cloudant.username| |cloudant userid
    +cloudant.password| |cloudant password
     cloudant.useQuery|false|By default, _all_docs endpoint is used if configuration 'view' and 'index' (see below) are not set. When useQuery is enabled, _find endpoint will be used in place of _all_docs when query condition is not on primary key field (_id), so that query predicates may be driven into datastore. 
     cloudant.queryLimit|25|The maximum number of results returned when querying the _find endpoint.
     jsonstore.rdd.partitions|10|the number of partitions intent used to drive JsonStoreRDD loading query result in parallel. The actual number is calculated based on total rows returned and satisfying maxInPartition and minInPartition
     jsonstore.rdd.maxInPartition|-1|the max rows in a partition. -1 means unlimited
     jsonstore.rdd.minInPartition|10|the min rows in a partition.
     jsonstore.rdd.requestTimeout|900000| the request timeout in milliseconds
     bulkSize|200| the bulk save size
    -schemaSampleSize| "-1" | the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    -createDBOnSave|"false"| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +schemaSampleSize|-1| the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    +createDBOnSave|false| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +
    +The `cloudant.apiReceiver` option allows for _changes or _all_docs API endpoint to be called while loading Cloudant data into Spark DataFrames or SQL Tables,
    --- End diff --
    
    Fixed in 5588c87.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126801105
  
    --- Diff: sql-cloudant/README.md ---
    @@ -31,15 +31,14 @@ The `--packages` argument can also be used with `bin/spark-submit`.
     
     Submit a job in Python:
         
    -    spark-submit  --master local[4] --jars <path to cloudant-spark.jar>  <path to python script> 
    +    spark-submit  --master local[4] --packages org.apache.bahir:spark-sql-cloudant_2.11:2.2.0-SNAPSHOT  <path to python script> 
         
     Submit a job in Scala:
     
    -	spark-submit --class "<your class>" --master local[4] --jars <path to cloudant-spark.jar> <path to your app jar>
    +	spark-submit --class "<your class>" --master local[4] --packages org.apache.bahir:spark-sql-cloudant_2.11:2.2.0-SNAPSHOT <path to spark-sql-cloudant jar>
    --- End diff --
    
    Fixed in 5588c87.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126801090
  
    --- Diff: sql-cloudant/README.md ---
    @@ -31,15 +31,14 @@ The `--packages` argument can also be used with `bin/spark-submit`.
     
     Submit a job in Python:
         
    -    spark-submit  --master local[4] --jars <path to cloudant-spark.jar>  <path to python script> 
    +    spark-submit  --master local[4] --packages org.apache.bahir:spark-sql-cloudant_2.11:2.2.0-SNAPSHOT  <path to python script> 
    --- End diff --
    
    Fixed in 5588c87.  There are existing examples on how to run this command under sections `Using SQL In Python` and `Using SQL In Scala`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by mayya-sharipova <gi...@git.apache.org>.
Github user mayya-sharipova commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r125746153
  
    --- Diff: sql-cloudant/README.md ---
    @@ -52,39 +51,61 @@ Here each subsequent configuration overrides the previous one. Thus, configurati
     
     
     ### Configuration in application.conf
    -Default values are defined in [here](cloudant-spark-sql/src/main/resources/application.conf).
    +Default values are defined in [here](src/main/resources/application.conf).
     
     ### Configuration on SparkConf
     
     Name | Default | Meaning
     --- |:---:| ---
    +cloudant.apiReceiver|"_all_docs"| API endpoint for RelationProvider when loading or saving data from Cloudant to DataFrames or SQL temporary tables. Select between "_all_docs" or "_changes" endpoint.
     cloudant.protocol|https|protocol to use to transfer data: http or https
    -cloudant.host||cloudant host url
    -cloudant.username||cloudant userid
    -cloudant.password||cloudant password
    +cloudant.host| |cloudant host url
    +cloudant.username| |cloudant userid
    +cloudant.password| |cloudant password
     cloudant.useQuery|false|By default, _all_docs endpoint is used if configuration 'view' and 'index' (see below) are not set. When useQuery is enabled, _find endpoint will be used in place of _all_docs when query condition is not on primary key field (_id), so that query predicates may be driven into datastore. 
     cloudant.queryLimit|25|The maximum number of results returned when querying the _find endpoint.
     jsonstore.rdd.partitions|10|the number of partitions intent used to drive JsonStoreRDD loading query result in parallel. The actual number is calculated based on total rows returned and satisfying maxInPartition and minInPartition
     jsonstore.rdd.maxInPartition|-1|the max rows in a partition. -1 means unlimited
     jsonstore.rdd.minInPartition|10|the min rows in a partition.
     jsonstore.rdd.requestTimeout|900000| the request timeout in milliseconds
     bulkSize|200| the bulk save size
    -schemaSampleSize| "-1" | the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    -createDBOnSave|"false"| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +schemaSampleSize|-1| the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    +createDBOnSave|false| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +
    +The `cloudant.apiReceiver` option allows for _changes or _all_docs API endpoint to be called while loading Cloudant data into Spark DataFrames or SQL Tables,
    +or saving data from DataFrames or SQL Tables to a Cloudant database.  
    +
    +**Note:** When using `_changes` API, please consider: 
    +1. Results are partially ordered and may not be be presented in order in 
    +which documents were updated.
    +2. In case of shards' unavailability, you may see duplicate results (changes that have been seen already)
    +3. Can use `selector` option to retrieve all revisions for docs
    +4. Only supports single threaded
    +
    --- End diff --
    
    You can add here that `_changes` support the real snapshot of the database representing it in a single point of time. While using `_all_docs` using partitions may not represent the true snapshot of the database, as some some docs may be added/deleted in the database between loading data into diff spark partitions. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    Build successful
     



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126801128
  
    --- Diff: sql-cloudant/README.md ---
    @@ -52,39 +51,71 @@ Here each subsequent configuration overrides the previous one. Thus, configurati
     
     
     ### Configuration in application.conf
    -Default values are defined in [here](cloudant-spark-sql/src/main/resources/application.conf).
    +Default values are defined in [here](src/main/resources/application.conf).
     
     ### Configuration on SparkConf
     
     Name | Default | Meaning
     --- |:---:| ---
    +cloudant.apiReceiver|"_all_docs"| API endpoint for RelationProvider when loading or saving data from Cloudant to DataFrames or SQL temporary tables. Select between "_all_docs" or "_changes" endpoint.
    --- End diff --
    
    Fixed in 5588c87.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [WIP] [BAHIR-110] Implement _changes API for non-streaming ...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    
    Refer to this link for build results (access rights to CI server needed): 
    http://169.45.79.58:8080/job/bahir_spark_pr_builder/73/



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    Build failed, see build log for details
     



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by mayya-sharipova <gi...@git.apache.org>.
Github user mayya-sharipova commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    +1 from my side after addressing small comments! Great work and very necessary!  Please squash all commits before merging!!!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by ricellis <gi...@git.apache.org>.
Github user ricellis commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126402723
  
    --- Diff: sql-cloudant/README.md ---
    @@ -52,39 +51,71 @@ Here each subsequent configuration overrides the previous one. Thus, configurati
     
     
     ### Configuration in application.conf
    -Default values are defined in [here](cloudant-spark-sql/src/main/resources/application.conf).
    +Default values are defined in [here](src/main/resources/application.conf).
     
     ### Configuration on SparkConf
     
     Name | Default | Meaning
     --- |:---:| ---
    +cloudant.apiReceiver|"_all_docs"| API endpoint for RelationProvider when loading or saving data from Cloudant to DataFrames or SQL temporary tables. Select between "_all_docs" or "_changes" endpoint.
     cloudant.protocol|https|protocol to use to transfer data: http or https
    -cloudant.host||cloudant host url
    -cloudant.username||cloudant userid
    -cloudant.password||cloudant password
    +cloudant.host| |cloudant host url
    +cloudant.username| |cloudant userid
    +cloudant.password| |cloudant password
     cloudant.useQuery|false|By default, _all_docs endpoint is used if configuration 'view' and 'index' (see below) are not set. When useQuery is enabled, _find endpoint will be used in place of _all_docs when query condition is not on primary key field (_id), so that query predicates may be driven into datastore. 
     cloudant.queryLimit|25|The maximum number of results returned when querying the _find endpoint.
     jsonstore.rdd.partitions|10|the number of partitions intent used to drive JsonStoreRDD loading query result in parallel. The actual number is calculated based on total rows returned and satisfying maxInPartition and minInPartition
     jsonstore.rdd.maxInPartition|-1|the max rows in a partition. -1 means unlimited
     jsonstore.rdd.minInPartition|10|the min rows in a partition.
     jsonstore.rdd.requestTimeout|900000| the request timeout in milliseconds
     bulkSize|200| the bulk save size
    -schemaSampleSize| "-1" | the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    -createDBOnSave|"false"| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +schemaSampleSize|-1| the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    --- End diff --
    
    using only **the** first document


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by ricellis <gi...@git.apache.org>.
Github user ricellis commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126438628
  
    --- Diff: sql-cloudant/src/main/scala/org/apache/bahir/cloudant/DefaultSource.scala ---
    @@ -98,29 +99,89 @@ class DefaultSource extends RelationProvider
     
           val config: CloudantConfig = JsonStoreConfigManager.getConfig(sqlContext, parameters)
     
    -      var allDocsDF: DataFrame = null
    +      var dataFrame: DataFrame = null
     
           val schema: StructType = {
             if (inSchema != null) {
               inSchema
    -        } else {
    -          val df = if (config.getSchemaSampleSize() ==
    -            JsonStoreConfigManager.ALL_DOCS_LIMIT &&
    +        } else if (!config.isInstanceOf[CloudantChangesConfig]
    +          || config.viewName != null || config.indexName != null) {
    +          val df = if (config.getSchemaSampleSize ==
    +            JsonStoreConfigManager.ALLDOCS_OR_CHANGES_LIMIT &&
                 config.viewName == null
                 && config.indexName == null) {
                 val cloudantRDD = new JsonStoreRDD(sqlContext.sparkContext, config)
    -            allDocsDF = sqlContext.read.json(cloudantRDD)
    -            allDocsDF
    +            dataFrame = sqlContext.read.json(cloudantRDD)
    +            dataFrame
               } else {
                 val dataAccess = new JsonStoreDataAccess(config)
                 val aRDD = sqlContext.sparkContext.parallelize(
    -                dataAccess.getMany(config.getSchemaSampleSize()))
    +                dataAccess.getMany(config.getSchemaSampleSize))
                 sqlContext.read.json(aRDD)
               }
               df.schema
    +        } else {
    +          /* Create a streaming context to handle transforming docs in
    +          * larger databases into Spark datasets
    +          */
    +          /* Allow the raw data and persisted RDDs to be accessible outside
    +          * of the streaming context.
    +          * See https://spark.apache.org/docs/latest/configuration.html
    +          * for more details.
    +          */
    +          sqlContext.sparkSession.conf.set("spark.streaming.unpersist", "false")
    +
    +          val ssc = new StreamingContext(sqlContext.sparkContext, Seconds(10))
    +          val streamingMap = {
    +            val selector = config.asInstanceOf[CloudantChangesConfig].getSelector
    +            if (selector != null) {
    +              Map(
    +                "database" -> config.getDbname,
    +                "selector" -> selector
    +              )
    +            } else {
    +              Map(
    +                "database" -> config.getDbname
    +              )
    +            }
    +          }
    +
    +          val changes = ssc.receiverStream(
    +            new CloudantReceiver(sqlContext.sparkContext.getConf, streamingMap))
    +          changes.persist(config.asInstanceOf[CloudantChangesConfig]
    +            .getStorageLevelForStreaming)
    +
    +          // Global RDD that's created from union of all RDDs
    +          var globalRDD = ssc.sparkContext.emptyRDD[String]
    +
    +          logger.info("Loading data from Cloudant using "
    +            + config.asInstanceOf[CloudantChangesConfig].getContinuousChangesUrl)
    +
    +          // Collect and union each RDD to convert all RDDs to a DataFrame
    +          changes.foreachRDD((rdd: RDD[String]) => {
    +            if (!rdd.isEmpty()) {
    +              if (globalRDD != null) {
    +                // Union RDDs in foreach loop
    +                globalRDD = globalRDD.union(rdd)
    +              } else {
    +                globalRDD = rdd
    +              }
    +            } else {
    +              // Convert final global RDD[String] to DataFrame
    +              dataFrame = sqlContext.sparkSession.read.json(globalRDD)
    +              ssc.stop(stopSparkContext = false, stopGracefully = false)
    +            }
    +          })
    +
    +          ssc.start
    +          // run streaming until all docs from continuous feed are received
    +          ssc.awaitTermination
    +          // ssc.stop(stopSparkContext = false, stopGracefully = false)
    --- End diff --
    
    Commented out code?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126801156
  
    --- Diff: sql-cloudant/README.md ---
    @@ -52,39 +51,71 @@ Here each subsequent configuration overrides the previous one. Thus, configurati
     
     
     ### Configuration in application.conf
    -Default values are defined in [here](cloudant-spark-sql/src/main/resources/application.conf).
    +Default values are defined in [here](src/main/resources/application.conf).
     
     ### Configuration on SparkConf
     
     Name | Default | Meaning
     --- |:---:| ---
    +cloudant.apiReceiver|"_all_docs"| API endpoint for RelationProvider when loading or saving data from Cloudant to DataFrames or SQL temporary tables. Select between "_all_docs" or "_changes" endpoint.
     cloudant.protocol|https|protocol to use to transfer data: http or https
    -cloudant.host||cloudant host url
    -cloudant.username||cloudant userid
    -cloudant.password||cloudant password
    +cloudant.host| |cloudant host url
    +cloudant.username| |cloudant userid
    +cloudant.password| |cloudant password
     cloudant.useQuery|false|By default, _all_docs endpoint is used if configuration 'view' and 'index' (see below) are not set. When useQuery is enabled, _find endpoint will be used in place of _all_docs when query condition is not on primary key field (_id), so that query predicates may be driven into datastore. 
     cloudant.queryLimit|25|The maximum number of results returned when querying the _find endpoint.
     jsonstore.rdd.partitions|10|the number of partitions intent used to drive JsonStoreRDD loading query result in parallel. The actual number is calculated based on total rows returned and satisfying maxInPartition and minInPartition
     jsonstore.rdd.maxInPartition|-1|the max rows in a partition. -1 means unlimited
     jsonstore.rdd.minInPartition|10|the min rows in a partition.
     jsonstore.rdd.requestTimeout|900000| the request timeout in milliseconds
     bulkSize|200| the bulk save size
    -schemaSampleSize| "-1" | the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    -createDBOnSave|"false"| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +schemaSampleSize|-1| the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    --- End diff --
    
    Fixed in 5588c87.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by ckadner <gi...@git.apache.org>.
Github user ckadner commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r125737077
  
    --- Diff: sql-cloudant/README.md ---
    @@ -52,39 +51,61 @@ Here each subsequent configuration overrides the previous one. Thus, configurati
     
     
     ### Configuration in application.conf
    -Default values are defined in [here](cloudant-spark-sql/src/main/resources/application.conf).
    +Default values are defined in [here](src/main/resources/application.conf).
     
     ### Configuration on SparkConf
     
     Name | Default | Meaning
     --- |:---:| ---
    +cloudant.apiReceiver|"_all_docs"| API endpoint for RelationProvider when loading or saving data from Cloudant to DataFrames or SQL temporary tables. Select between "_all_docs" or "_changes" endpoint.
     cloudant.protocol|https|protocol to use to transfer data: http or https
    -cloudant.host||cloudant host url
    -cloudant.username||cloudant userid
    -cloudant.password||cloudant password
    +cloudant.host| |cloudant host url
    +cloudant.username| |cloudant userid
    +cloudant.password| |cloudant password
     cloudant.useQuery|false|By default, _all_docs endpoint is used if configuration 'view' and 'index' (see below) are not set. When useQuery is enabled, _find endpoint will be used in place of _all_docs when query condition is not on primary key field (_id), so that query predicates may be driven into datastore. 
     cloudant.queryLimit|25|The maximum number of results returned when querying the _find endpoint.
     jsonstore.rdd.partitions|10|the number of partitions intent used to drive JsonStoreRDD loading query result in parallel. The actual number is calculated based on total rows returned and satisfying maxInPartition and minInPartition
     jsonstore.rdd.maxInPartition|-1|the max rows in a partition. -1 means unlimited
     jsonstore.rdd.minInPartition|10|the min rows in a partition.
     jsonstore.rdd.requestTimeout|900000| the request timeout in milliseconds
     bulkSize|200| the bulk save size
    -schemaSampleSize| "-1" | the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    -createDBOnSave|"false"| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +schemaSampleSize|-1| the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    +createDBOnSave|false| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +
    +The `cloudant.apiReceiver` option allows for _changes or _all_docs API endpoint to be called while loading Cloudant data into Spark DataFrames or SQL Tables,
    +or saving data from DataFrames or SQL Tables to a Cloudant database.  
    +
    +**Note:** When using `_changes` API, please consider: 
    +1. Results are partially ordered and may not be be presented in order in 
    +which documents were updated.
    +2. In case of shards' unavailability, you may see duplicate results (changes that have been seen already)
    +3. Can use `selector` option to retrieve all revisions for docs
    +4. Only supports single threaded
    +
    +When using `_all_docs` API:
    +1. Supports parallel reads (using offset and range)
    +
    +Performance of `_changes` API is still better in most cases (even with single threaded support). 
    +During several performance tests using 50 to 200 MB Cloudant databases, load time from Cloudant to Spark using `_changes` 
    +feed was faster to complete every time compared to `_all_docs`.
    + 
    --- End diff --
    
    the code style guide (enforced by build) is 100 characters per line


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by ricellis <gi...@git.apache.org>.
Github user ricellis commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126403065
  
    --- Diff: sql-cloudant/README.md ---
    @@ -52,39 +51,71 @@ Here each subsequent configuration overrides the previous one. Thus, configurati
     
     
     ### Configuration in application.conf
    -Default values are defined in [here](cloudant-spark-sql/src/main/resources/application.conf).
    +Default values are defined in [here](src/main/resources/application.conf).
     
     ### Configuration on SparkConf
     
     Name | Default | Meaning
     --- |:---:| ---
    +cloudant.apiReceiver|"_all_docs"| API endpoint for RelationProvider when loading or saving data from Cloudant to DataFrames or SQL temporary tables. Select between "_all_docs" or "_changes" endpoint.
     cloudant.protocol|https|protocol to use to transfer data: http or https
    -cloudant.host||cloudant host url
    -cloudant.username||cloudant userid
    -cloudant.password||cloudant password
    +cloudant.host| |cloudant host url
    +cloudant.username| |cloudant userid
    +cloudant.password| |cloudant password
     cloudant.useQuery|false|By default, _all_docs endpoint is used if configuration 'view' and 'index' (see below) are not set. When useQuery is enabled, _find endpoint will be used in place of _all_docs when query condition is not on primary key field (_id), so that query predicates may be driven into datastore. 
     cloudant.queryLimit|25|The maximum number of results returned when querying the _find endpoint.
     jsonstore.rdd.partitions|10|the number of partitions intent used to drive JsonStoreRDD loading query result in parallel. The actual number is calculated based on total rows returned and satisfying maxInPartition and minInPartition
     jsonstore.rdd.maxInPartition|-1|the max rows in a partition. -1 means unlimited
     jsonstore.rdd.minInPartition|10|the min rows in a partition.
     jsonstore.rdd.requestTimeout|900000| the request timeout in milliseconds
     bulkSize|200| the bulk save size
    -schemaSampleSize| "-1" | the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    -createDBOnSave|"false"| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +schemaSampleSize|-1| the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    +createDBOnSave|false| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +
    +The `cloudant.apiReceiver` option allows for _changes or _all_docs API endpoint to be called while loading Cloudant data into Spark DataFrames or SQL Tables,
    --- End diff --
    
    `allows` doesn't seem right here, maybe `sets` as in
    >option sets the `_changes` or `_all_docs`
    
    ?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by mayya-sharipova <gi...@git.apache.org>.
Github user mayya-sharipova commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r127467315
  
    --- Diff: sql-cloudant/src/main/scala/org/apache/bahir/cloudant/DefaultSource.scala ---
    @@ -98,29 +99,81 @@ class DefaultSource extends RelationProvider
     
           val config: CloudantConfig = JsonStoreConfigManager.getConfig(sqlContext, parameters)
     
    -      var allDocsDF: DataFrame = null
    +      var dataFrame: DataFrame = null
     
           val schema: StructType = {
             if (inSchema != null) {
               inSchema
    -        } else {
    -          val df = if (config.getSchemaSampleSize() ==
    -            JsonStoreConfigManager.ALL_DOCS_LIMIT &&
    +        } else if (!config.isInstanceOf[CloudantChangesConfig]
    +          || config.viewName != null || config.indexName != null) {
    +          val df = if (config.getSchemaSampleSize ==
    +            JsonStoreConfigManager.ALLDOCS_OR_CHANGES_LIMIT &&
                 config.viewName == null
                 && config.indexName == null) {
                 val cloudantRDD = new JsonStoreRDD(sqlContext.sparkContext, config)
    -            allDocsDF = sqlContext.read.json(cloudantRDD)
    -            allDocsDF
    +            dataFrame = sqlContext.read.json(cloudantRDD)
    +            dataFrame
               } else {
                 val dataAccess = new JsonStoreDataAccess(config)
                 val aRDD = sqlContext.sparkContext.parallelize(
    -                dataAccess.getMany(config.getSchemaSampleSize()))
    +                dataAccess.getMany(config.getSchemaSampleSize))
                 sqlContext.read.json(aRDD)
               }
               df.schema
    +        } else {
    +          /* Create a streaming context to handle transforming docs in
    +          * larger databases into Spark datasets
    +          */
    +          val ssc = new StreamingContext(sqlContext.sparkContext, Seconds(10))
    +          val streamingMap = {
    +            val selector = config.asInstanceOf[CloudantChangesConfig].getSelector
    +            if (selector != null) {
    +              Map(
    +                "database" -> config.getDbname,
    +                "selector" -> selector
    +              )
    +            } else {
    +              Map(
    +                "database" -> config.getDbname
    +              )
    +            }
    +          }
    +
    +          val changes = ssc.receiverStream(
    +            new CloudantReceiver(sqlContext.sparkContext.getConf, streamingMap))
    +          changes.persist(config.asInstanceOf[CloudantChangesConfig]
    +            .getStorageLevelForStreaming)
    +
    +          // Global RDD that's created from union of all RDDs
    +          var globalRDD = ssc.sparkContext.emptyRDD[String]
    +
    +          logger.info("Loading data from Cloudant using "
    +            + config.asInstanceOf[CloudantChangesConfig].getContinuousChangesUrl)
    +
    --- End diff --
    
    @emlaver  Here while trying to load a db, I am getting a message "Loading data from Cloudant using https://XXXX.cloudant.com/n_airportcodemapping/_changes?include_docs=true&feed=continuous&heartbeat=3000"
    
    We should NOT load data into Spark SQL using `continuous` feed (which for constantly updating database may be never be over).  The whole point of loading a db into Spark SQL is to load a snapshot of a db at a particular point of time.  Use `normal` feed here. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [WIP] [BAHIR-110] Implement _changes API for non-streaming ...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    
    Refer to this link for build results (access rights to CI server needed): 
    http://169.45.79.58:8080/job/bahir_spark_pr_builder/70/



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126446901
  
    --- Diff: sql-cloudant/src/main/scala/org/apache/bahir/cloudant/CloudantConfig.scala ---
    @@ -30,81 +28,83 @@ import org.apache.bahir.cloudant.common._
     */
     
     class CloudantConfig(val protocol: String, val host: String,
    -    val dbName: String, val indexName: String = null, val viewName: String = null)
    +    val dbName: String, val indexName: String, val viewName: String)
         (implicit val username: String, val password: String,
         val partitions: Int, val maxInPartition: Int, val minInPartition: Int,
         val requestTimeout: Long, val bulkSize: Int, val schemaSampleSize: Int,
    -    val createDBOnSave: Boolean, val selector: String, val useQuery: Boolean = false,
    -    val queryLimit: Int)
    -    extends Serializable{
    +    val createDBOnSave: Boolean, val apiReceiver: String,
    +    val useQuery: Boolean = false, val queryLimit: Int)
    +    extends Serializable {
     
    -  private lazy val dbUrl = {protocol + "://" + host + "/" + dbName}
    +  lazy val dbUrl: String = {protocol + "://" + host + "/" + dbName}
     
       val pkField = "_id"
    -  val defaultIndex = "_all_docs" // "_changes" does not work for partition
    +  val defaultIndex: String = apiReceiver
       val default_filter: String = "*:*"
     
    -  def getContinuousChangesUrl(): String = {
    -    var url = dbUrl + "/_changes?include_docs=true&feed=continuous&heartbeat=3000"
    -    if (selector != null) {
    -      url = url + "&filter=_selector"
    -    }
    -    url
    -  }
    -
    -  def getSelector() : String = {
    -    selector
    -  }
    -
    -  def getDbUrl(): String = {
    +  def getDbUrl: String = {
         dbUrl
       }
     
    -  def getSchemaSampleSize(): Int = {
    +  def getSchemaSampleSize: Int = {
         schemaSampleSize
       }
     
    -  def getCreateDBonSave(): Boolean = {
    +  def getCreateDBonSave: Boolean = {
         createDBOnSave
       }
     
    -  def getTotalUrl(url: String): String = {
    -    if (url.contains('?')) {
    -      url + "&limit=1"
    -    } else {
    -      url + "?limit=1"
    -    }
    -  }
    -
    -  def getDbname(): String = {
    -    dbName
    -  }
    -
    -  def queryEnabled(): Boolean = {useQuery && indexName==null && viewName==null}
    -
    -  def allowPartition(queryUsed: Boolean): Boolean = {indexName==null && !queryUsed}
    -
    -  def getAllDocsUrl(limit: Int, excludeDDoc: Boolean = false): String = {
    +  def getLastNum(result: JsValue): JsValue = (result \ "last_seq").get
     
    +  /* Url containing limit for docs in a Cloudant database.
    +  * If a view is not defined, use the _all_docs endpoint.
    +  * @return url with one doc limit for retrieving total doc count
    +  */
    +  def getUrl(limit: Int, excludeDDoc: Boolean = false): String = {
         if (viewName == null) {
    -      val baseUrl = (
    -          if ( excludeDDoc) dbUrl + "/_all_docs?startkey=%22_design0/%22&include_docs=true"
    -          else dbUrl + "/_all_docs?include_docs=true"
    -          )
    -      if (limit == JsonStoreConfigManager.ALL_DOCS_LIMIT) {
    +      val baseUrl = {
    +        if (excludeDDoc) {
    +          dbUrl + "/_all_docs?startkey=%22_design0/%22&include_docs=true"
    --- End diff --
    
    I'll open a new JIRA issue for this.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by mayya-sharipova <gi...@git.apache.org>.
Github user mayya-sharipova commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r125764230
  
    --- Diff: sql-cloudant/src/main/scala/org/apache/bahir/cloudant/CloudantAllDocsConfig.scala ---
    @@ -0,0 +1,67 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.bahir.cloudant
    +
    +import org.apache.bahir.cloudant.common.JsonStoreConfigManager
    +
    +class CloudantAllDocsConfig(protocol: String, host: String, dbName: String,
    +                            indexName: String = null, viewName: String = null)
    +                           (username: String, password: String, partitions: Int,
    +                            maxInPartition: Int, minInPartition: Int, requestTimeout: Long,
    +                            bulkSize: Int, schemaSampleSize: Int,
    +                            createDBOnSave: Boolean, apiReceiver: String, selector: String,
    +                            useQuery: Boolean, queryLimit: Int)
    +  extends CloudantConfig(protocol, host, dbName, indexName, viewName)(username, password,
    +  partitions, maxInPartition, minInPartition, requestTimeout, bulkSize, schemaSampleSize,
    +  createDBOnSave, apiReceiver, selector, useQuery, queryLimit) {
    +
    +  override val defaultIndex: String = apiReceiver
    +
    --- End diff --
    
    Adding small comments for functions `getOneUrl`, `getUrl`, and `getSubSetUrl` describing how these functions are used would be a great help for understanding the code.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126977435
  
    --- Diff: sql-cloudant/src/test/scala/org/apache/bahir/cloudant/CloudantSparkSQLSuite.scala ---
    @@ -0,0 +1,101 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.bahir.cloudant
    +
    +import org.apache.spark.sql.{SparkSession, SQLContext, SQLImplicits}
    +
    +class CloudantSparkSQLSuite extends ClientSparkFunSuite {
    +  // import spark implicits
    +  private object testImplicits extends SQLImplicits {
    +    protected override def _sqlContext: SQLContext = spark.sqlContext
    +  }
    +
    +  import testImplicits._
    +
    +  val apiReceiver = "_all_docs"
    +
    +  override def beforeAll() {
    +    runIfTestsEnabled("Prepare Cloudant test databases") {
    +      super.beforeAll()
    +      spark = SparkSession.builder().config(conf)
    +        .config("cloudant.protocol", TestUtils.getProtocol)
    +        .config("cloudant.host", TestUtils.getHost)
    +        .config("cloudant.username", TestUtils.getUsername)
    +        .config("cloudant.password", TestUtils.getPassword)
    +        .config("cloudant.apiReceiver", apiReceiver)
    --- End diff --
    
    @mayya-sharipova It's `endpoint`, looks like I missed this test suite.  Thanks for catching that.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [WIP] [BAHIR-110] Implement _changes API for non-streaming ...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    Stability tests update:  I did three successful loads into Spark yesterday with a 15GB (time: 8 1/2 mins), 20GB (17 mins), and 46GB (25 mins) database.
    @mayya-sharipova @yanglei99 @ricellis 



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by ricellis <gi...@git.apache.org>.
Github user ricellis commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126435531
  
    --- Diff: sql-cloudant/src/main/scala/org/apache/bahir/cloudant/CloudantReceiver.scala ---
    @@ -16,23 +16,20 @@
      */
     package org.apache.bahir.cloudant
     
    -// scalastyle:off
    -import scalaj.http._
    -
     import play.api.libs.json.Json
    +import scalaj.http._
     
    +import org.apache.spark.SparkConf
     import org.apache.spark.storage.StorageLevel
     import org.apache.spark.streaming.receiver.Receiver
    -import org.apache.spark.SparkConf
     
     import org.apache.bahir.cloudant.common._
    -// scalastyle:on
     
     class CloudantReceiver(sparkConf: SparkConf, cloudantParams: Map[String, String])
         extends Receiver[String](StorageLevel.MEMORY_AND_DISK) {
    -  lazy val config: CloudantConfig = {
    +  lazy val config: CloudantChangesConfig = {
    --- End diff --
    
    Would this class be better named `CloudantChangesReceiver`? Since it doesn't appear to be a general case.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    
    Refer to this link for build results (access rights to CI server needed): 
    http://169.45.79.58:8080/job/bahir_spark_pr_builder/81/



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by ckadner <gi...@git.apache.org>.
Github user ckadner commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    thanks @emlaver -- lets kick off a test build without the environment variables set


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [WIP] [BAHIR-110] Implement _changes API for non-streaming ...

Posted by ApacheBahir <gi...@git.apache.org>.
Github user ApacheBahir commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    Build successful
     



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by ricellis <gi...@git.apache.org>.
Github user ricellis commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126401691
  
    --- Diff: sql-cloudant/README.md ---
    @@ -31,15 +31,14 @@ The `--packages` argument can also be used with `bin/spark-submit`.
     
     Submit a job in Python:
         
    -    spark-submit  --master local[4] --jars <path to cloudant-spark.jar>  <path to python script> 
    +    spark-submit  --master local[4] --packages org.apache.bahir:spark-sql-cloudant_2.11:2.2.0-SNAPSHOT  <path to python script> 
    --- End diff --
    
    Should the example really point to a `SNAPSHOT` version?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir issue #45: [BAHIR-110] Implement _changes API for non-streaming receiv...

Posted by ckadner <gi...@git.apache.org>.
Github user ckadner commented on the issue:

    https://github.com/apache/bahir/pull/45
  
    Thanks @emlaver for this PR and @mayya-sharipova for your thorough review!
    
    **LGTM**


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by ricellis <gi...@git.apache.org>.
Github user ricellis commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126409663
  
    --- Diff: sql-cloudant/README.md ---
    @@ -52,39 +51,71 @@ Here each subsequent configuration overrides the previous one. Thus, configurati
     
     
     ### Configuration in application.conf
    -Default values are defined in [here](cloudant-spark-sql/src/main/resources/application.conf).
    +Default values are defined in [here](src/main/resources/application.conf).
     
     ### Configuration on SparkConf
     
     Name | Default | Meaning
     --- |:---:| ---
    +cloudant.apiReceiver|"_all_docs"| API endpoint for RelationProvider when loading or saving data from Cloudant to DataFrames or SQL temporary tables. Select between "_all_docs" or "_changes" endpoint.
     cloudant.protocol|https|protocol to use to transfer data: http or https
    -cloudant.host||cloudant host url
    -cloudant.username||cloudant userid
    -cloudant.password||cloudant password
    +cloudant.host| |cloudant host url
    +cloudant.username| |cloudant userid
    +cloudant.password| |cloudant password
     cloudant.useQuery|false|By default, _all_docs endpoint is used if configuration 'view' and 'index' (see below) are not set. When useQuery is enabled, _find endpoint will be used in place of _all_docs when query condition is not on primary key field (_id), so that query predicates may be driven into datastore. 
     cloudant.queryLimit|25|The maximum number of results returned when querying the _find endpoint.
     jsonstore.rdd.partitions|10|the number of partitions intent used to drive JsonStoreRDD loading query result in parallel. The actual number is calculated based on total rows returned and satisfying maxInPartition and minInPartition
     jsonstore.rdd.maxInPartition|-1|the max rows in a partition. -1 means unlimited
     jsonstore.rdd.minInPartition|10|the min rows in a partition.
     jsonstore.rdd.requestTimeout|900000| the request timeout in milliseconds
     bulkSize|200| the bulk save size
    -schemaSampleSize| "-1" | the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    -createDBOnSave|"false"| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +schemaSampleSize|-1| the sample size for RDD schema discovery. 1 means we are using only first document for schema discovery; -1 means all documents; 0 will be treated as 1; any number N means min(N, total) docs 
    +createDBOnSave|false| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +
    +The `cloudant.apiReceiver` option allows for _changes or _all_docs API endpoint to be called while loading Cloudant data into Spark DataFrames or SQL Tables,
    +or saving data from DataFrames or SQL Tables to a Cloudant database.
    +
    +**Note:** When using `_changes` API, please consider: 
    +1. Results are partially ordered and may not be be presented in order in 
    +which documents were updated.
    +2. In case of shards' unavailability, you may see duplicate results (changes that have been seen already)
    +3. Can use `selector` option to filter Cloudant docs during load
    +4. Supports a real snapshot of the database and represents it in a single point of time.
    +5. Only supports single threaded
    +
    +
    +When using `_all_docs` API:
    +1. Supports parallel reads (using offset and range)
    +2. Using partitions may not represent the true snapshot of a database.  Some docs
    +   may be added or deleted in the database between loading data into different 
    +   Spark partitions.
    +
    +Performance of `_changes` API is still better in most cases (even with single threaded support). 
    +During several performance tests using 200 MB to 15 GB Cloudant databases, load time from Cloudant to Spark using 
    +`_changes` feed was faster to complete every time compared to `_all_docs`.
    + 
    +See [CloudantChangesDFSuite](src/test/scala/org/apache/bahir/cloudant/CloudantChangesDFSuite.scala) 
    +for examples of loading data into a Spark DataFrame with `_changes` API.
     
     ### Configuration on Spark SQL Temporary Table or DataFrame
     
     Besides all the configurations passed to a temporary table or dataframe through SparkConf, it is also possible to set the following configurations in temporary table or dataframe using OPTIONS: 
     
     Name | Default | Meaning
     --- |:---:| ---
    -database||cloudant database name
    -view||cloudant view w/o the database name. only used for load.
    -index||cloudant search index w/o the database name. only used for load data with less than or equal to 200 results.
    -path||cloudant: as database name if database is not present
    -schemaSampleSize|"-1"| the sample size used to discover the schema for this temp table. -1 scans all documents
     bulkSize|200| the bulk save size
    -createDBOnSave|"false"| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +createDBOnSave|false| whether to create a new database during save operation. If false, a database should already exist. If true, a new database will be created. If true, and a database with a provided name already exists, an error will be raised. 
    +database| | Cloudant database name
    +index| | Cloudant search index w/o the database name. only used for load data with less than or equal to 200 results.
    --- End diff --
    
    I would say `Index queries are limited to returning 200 results so can only be used to load data with <= 200 results.`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] bahir pull request #45: [WIP] [BAHIR-110] Implement _changes API for non-str...

Posted by emlaver <gi...@git.apache.org>.
Github user emlaver commented on a diff in the pull request:

    https://github.com/apache/bahir/pull/45#discussion_r126073154
  
    --- Diff: sql-cloudant/src/main/scala/org/apache/bahir/cloudant/CloudantAllDocsConfig.scala ---
    @@ -0,0 +1,67 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.bahir.cloudant
    +
    +import org.apache.bahir.cloudant.common.JsonStoreConfigManager
    +
    +class CloudantAllDocsConfig(protocol: String, host: String, dbName: String,
    +                            indexName: String = null, viewName: String = null)
    +                           (username: String, password: String, partitions: Int,
    +                            maxInPartition: Int, minInPartition: Int, requestTimeout: Long,
    +                            bulkSize: Int, schemaSampleSize: Int,
    +                            createDBOnSave: Boolean, apiReceiver: String, selector: String,
    +                            useQuery: Boolean, queryLimit: Int)
    +  extends CloudantConfig(protocol, host, dbName, indexName, viewName)(username, password,
    +  partitions, maxInPartition, minInPartition, requestTimeout, bulkSize, schemaSampleSize,
    +  createDBOnSave, apiReceiver, selector, useQuery, queryLimit) {
    +
    +  override val defaultIndex: String = apiReceiver
    +
    --- End diff --
    
    Added some details in 47064b7.
    



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---