Q98. What is Hive? A98. Hive is used for accessing and analyzing data in Hadoop using SQL syntax. It is known as the HiveQL. Q99. What is the difference between Hive internal tables & external tables? A99. … Read more ›...
Q98. What is Hive? A98. Hive is used for accessing and analyzing data in Hadoop using SQL syntax. It is known as the HiveQL. Q99. What is the difference between Hive internal tables & external tables? A99. … Read more ›...
Semigroups, Monoids, Functors, Monads, Applicatives, etc are concepts or patterns that abstract complexities in computations, and NOT traits or classes. You can think of them as type classes like List[T], Option[T], Futures[T], MyContainer[T], etc that fulfil requirements of functors, monads, etc. Let’s start with monoids first. … Read more ›...
Monoids, Functors, Monads, Applicatives, etc are concepts or patterns that abstract complexities in computations, and NOT traits or classes. You can think of them as container type classes like List[T], Option[T], Futures[T], MyContainer[T], etc that fulfil requirements of functors, monads, etc. Let’s start with monoids first. … Read more ›...
This extends 13: Q81 – Q83 Scala monoids interview Q&As. Given the below code
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
package com.myapp object FoldIsAMonoid extends App { val xs: List[Double] = List(1.0,2.0,3.0, 4.0) val ys: List[Int] = List(11,22, 33) val map1 = Map ("John" -> 22, "Peter" -> 33, "Sam"-> 97 ) val map2 = Map ( "John" -> 7, "Peter" -> 9 ) } |
Q01. How will you combine the two lists xs & xy? A01. The foldLeft(.)(..) to the rescue as shown below:
|
1 |
override def foldLeft[B](z: B)(op: (B, A) => B): B |
|
1 2 3 |
val result = ys.foldLeft(xs)((xs_acc,y) => xs_acc.:+(y.asInstanceOf[Double])) println(result); |
:+ is a method name alias for the append:
|
1 2 3 |
final def:+[B >: A](elem: B): List[B] |
Output:
|
1 2 |
List(1.0, 2.0, 3.0, 4.0, 11.0, 22.0, 33.0) |
Q02....
This post reiterates the importance of understanding the order of execution of the SQL statements. Also, always think of the data granularity (aka grain). This post also demonstrates that the final query may look complex, but if you break it down it is much easier to comprehend.
…
Scala concurrency with Future explains step by step blocking vs unblocking calls and how implicit and apply concepts work under the covers. Scala extends the Java programming language and runtime in many ways, including concurrency where Scala version of Future<T> is more flexible than the Java version as you can create futures directly from blocks of code,
…
This extends 13: PySpark with Apache Kafka Interview Q&As with tutorials – part 1 Q42: How would you go about displaying the array of JSON data in a tabular format? A42 In this post we will expand & … Read more ›...
Closures In Python you have a closure when a nested function references a value in its enclosing scope as shown below. The inner function “inner_sum” references the enclosing function “outer_sum”‘s variable “num1”.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
$ python3 >>> def outer_sum(num1): ... def inner_sum(num2): ... return(num1 + num2) ... return inner_sum ... >>> add_5 = outer_sum(5) # num1 will be closed over as 5 >>> type(add_5) <type 'function'> >>> add_5(10) 15 >>> add_5(12) 17 >>> >>> add_3 = outer_sum(3) # num1 will be closed over as 3 >>> add_3(6) 9 >>> add_5(add_3(6)) 14 >>> add_3(add_5(9)) 17 >>> |
The criteria that must be met to create a closure in Python : 1) You must have...
Q105. What is the difference between “map” and “flatMap” operations in Spark?
A105. The map and flatMap are transformation operations in Spark.
map transformation is applied to each element of RDD and it returns the result as a new RDD.
…
Q84. What is a category theory from a functional programming language perspective? A84. The category theory is all about abstractions. Composition “f” and “g” are functions, and “A” and “B” are types. f: A => … Read more ›...
In this post let’s look at an SQL scenario, and three different ways to solve this scenario. There could be more ways to solve an SQL scenario. Problem Statement Given the below “orders” table write a query to find the order status.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
line_item_id order_id line_item_status ---------------------------------------------- 1 ORD123 DELIVERED 2 ORD123 DELIVERED 3 ORD123 DELIVERED 1 ORD124 DELIVERED 2 ORD124 SHIPPED 1 ORD125 PENDING 2 ORD125 SHIPPED 3 ORD125 DELIVERED 1 ORD126 SHIPPED 2 ORD126 SHIPPED 1 ORD127 PENDING 2 ORD127 PENDING |
1) If all line items are ‘DELIVERED’...
This post not only covers “onSuccess” method on a “Future”, but also clarifies the difference between executing a closure and a function definition. Is anything wrong with the following Scala concurrency code?
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import scala.concurrent.ExecutionContext.Implicits.global //thread pool execution context import scala.concurrent.{Await, Future} import scala.actors.threadpool.AtomicInteger import scala.concurrent.duration._ // 5 seconds object SimpleFuture extends App { val counter = new AtomicInteger //can succeed or fail val futureInc = Future { Thread.sleep(2000) // 2000ms processing time println("Incrementing .....") counter.incrementAndGet() } val f1: Future[Int] = futureInc val f2: Future[Int] = futureInc f1.onSuccess { case val1 => { println("val1 = " + val1) f2.onSuccess { case val2 => println("val2 = " + val2) println("Sum of generated numbers = " + (val1 + val2)) } } } Thread.sleep(5000) } |
Output:
|
1 2 3 4 5 6 |
Incrementing ..... val1 = 1 val2 = 1 Sum of generated numbers = 2 |
“ … Read more ›...
This extends PySpark with Apache Kafka Interview Q&As with tutorials – part 1 and PySpark with Apache Kafka Interview Q&As with tutorials – part 2 Q46: How will you go about writing the streamed structured to a parquet file? A46: In the last tutorial we wrote a console sink, …...
I have a good news, I got job offer. I like to share with you from my bottom of my heart feeling thankful to you.