chetanmeh commented on a change in pull request #3562: ArtifactStore 
implementation for CosmosDB
URL: 
https://github.com/apache/incubator-openwhisk/pull/3562#discussion_r200802815
 
 

 ##########
 File path: 
common/scala/src/main/scala/whisk/core/database/cosmosdb/CosmosDBUtil.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 whisk.core.database.cosmosdb
+
+import com.microsoft.azure.cosmosdb._
+import com.microsoft.azure.cosmosdb.internal.Constants.Properties.{AGGREGATE, 
E_TAG, ID, SELF_LINK}
+import com.microsoft.azure.cosmosdb.rx.AsyncDocumentClient
+import whisk.core.database.cosmosdb.CosmosDBConstants._
+
+import scala.collection.immutable.Iterable
+
+private[cosmosdb] object CosmosDBConstants {
+  val computed: String = "_c"
+
+  val alias: String = "view"
+
+  val cid: String = ID
+
+  val etag: String = E_TAG
+
+  val aggregate: String = AGGREGATE
+
+  val selfLink: String = SELF_LINK
+}
+
+private[cosmosdb] trait CosmosDBUtil {
+
+  /**
+   * Prepares the json like select clause
+   * {{{
+   *   Seq("a", "b", "c.d.e") =>
+   *   { "a" : r['a'], "b" : r['b'], "c" : { "d" : { "e" : r['c']['d']['e']}}, 
"id" : r['id']} AS view
+   * }}}
+   * Here it uses {{{r['keyName']}}} notation to avoid issues around using 
reserved words as field name
+   */
+  def prepareFieldClause(fields: Iterable[String]): String = {
+    val m = fields.foldLeft(Map.empty[String, Any]) { (map, name) =>
+      addToMap(name, map)
+    }
+    val withId = addToMap(cid, m)
+    val json = asJsonLikeString(withId)
+    s"$json AS $alias"
+  }
+
+  private def addToMap(name: String, map: Map[String, _]): Map[String, Any] = 
name.split('.').toList match {
+    case Nil     => sys.error(s"Should not reach here $name")
 
 Review comment:
   String split should never result in empty list. Changed it to throw ISE

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to