Posts

Showing posts with the label scala

Scala version warning for scala-java8-compat_2.12:0.8.0

Image
Clash Royale CLAN TAG #URR8PPP Scala version warning for scala-java8-compat_2.12:0.8.0 I am using scala 2.12.1 for a project built with maven but am getting version warnings like the one below: [WARNING] org.scala-lang.modules:scala-java8-compat_2.12:0.8.0 requires scala version: 2.12.0 [WARNING] Multiple versions of scala libraries detected! What can I do to get the versioning right here? From what I understand these are libraries scala itself brings in and not explicitly defined by me. I get the same for xml lib too. xml 1 Answer 1 To get rid of such warnings just add this to the <configuration> block of the <maven-scala-plugin> definition in your pom.xml: <configuration> <maven-scala-plugin> <scalaCompatVersion>${scala.compat.version}</scalaCompatVersion> And add <scala.compat.version>2.12</scala.compat.version> to the <properties> secti...

Separating application logs in Logback from Spark Logs in log4j

Image
Clash Royale CLAN TAG #URR8PPP Separating application logs in Logback from Spark Logs in log4j I have a Scala Maven project using that uses Spark, and I am trying implement logging using Logback. I am compiling my application to a jar, and deploying to an EC2 instance where the Spark distribution is installed. My pom.xml includes dependencies for Spark and Logback as follows: <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.1.7</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>log4j-over-slf4j</artifactId> <version>1.7.7</version> </dependency> <dependency> <groupId>org.apache.spark</groupId> <artifactId>spark-core_${scala.binary.version}</artifactId> ...

Swagger-Akka-Http: List of objects in the request body

Image
Clash Royale CLAN TAG #URR8PPP Swagger-Akka-Http: List of objects in the request body I'm using swagger-akka-http to built Swagger docs for my Akka HTTP service. My service has a POST method accepting a List of Characteristic . List Characteristic @ApiOperation(value = "Fetch offerings by characteristics", httpMethod = "POST") @ApiImplicitParams(Array( new ApiImplicitParam(name = "characteristics", required = true, dataTypeClass = classOf[List[Characteristic]], paramType = "body") )) @ApiResponses(Array( new ApiResponse(code = 200, response = classOf[Offering], responseContainer = "List") )) def fetchOfferings: Route = post { entity(as[List[Characteristic]]) { characteristics => // some logic } } dataTypeClass = classOf[List[Characteristic]] in ApiImplicitParams is not working as expected. There is the following result in the generated Swagger YAML: dataTypeClass = classOf[List[Character...

scala: select column where not contains elements into dataframe

Image
Clash Royale CLAN TAG #URR8PPP scala: select column where not contains elements into dataframe I have this ligne of code that should create a dataframe from list of columns that not contain a string. I tried this but it doesn't work: val exemple = hiveObj.sql("show tables in database").select("tableName")!==="ABC".collect() By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

sbt release to Maven central fails with no public key error

Image
Clash Royale CLAN TAG #URR8PPP sbt release to Maven central fails with no public key error I tried to release better-files to Maven central and I am getting this error. I tried this on fresh checkout on multiple different machines. My steps: > sbt sbt:better-files-root> pgp-cmd gen-key Please enter the name associated with the key: Pathikrit Bhowmick Please enter the email associated with the key: pathikritbhowmick@msn.com Please enter the passphrase for the key: ********* Please re-enter the passphrase for the key: ********* [info] Creating a new PGP key, this could take a long time. [info] Public key := /Users/pathikrit/.sbt/gpg/pubring.asc [info] Secret key := /Users/pathikrit/.sbt/gpg/secring.asc [info] Please do not share your secret key. Your public key is free to share. sbt:better-files-root> pgp-cmd send-key pathikritbhowmick@msn.com hkp://pool.sks-keyservers.net [info] Sending PublicKeyRing(PublicKey(27dfe5f26bf754dc, Pathikrit Bhowmick <pathikritbhowmick@msn....

Why does IntelliJ seem to import my scala libraries twice?

Image
Clash Royale CLAN TAG #URR8PPP Why does IntelliJ seem to import my scala libraries twice? I have just started trying to use Scala with IntelliJ. I created a new project as per the instructions in: https://docs.scala-lang.org/getting-started-intellij-track/getting-started-with-scala-in-intellij.html I installed scala 2.12.6 using Homebrew and selected that when creating my new Scala project in IntelliJ. For some reason, under External Libraries, I have every jar inside the scala installation twice: I created a hello world and when I try to run it, and I got this error: Error:scalac: Multiple 'scala-library*.jar' files (scala-library.jar, scala-library.jar) in Scala compiler classpath in Scala SDK scala-sdk-2.12.6 However inside the Scala libraries folder there is only one jar of each. I'm not sure what I'm doing wrong here. I've tried other versions of Scala, but got the same results. By clicking ...

Doobie transact over a list of ConnectionIO programs

Image
Clash Royale CLAN TAG #URR8PPP Doobie transact over a list of ConnectionIO programs Let's say I have a list of Doobie programs (all with Unit type parameters, fwiw): Unit val progList: List[ConnectionIO[Unit]] = prog1 :: prog2 :: ... :: Nil Is there any way I can run them in one transaction? A for-comprehension won't work here, because I only know the precise composition of the program list at runtime. Essentially, I suppose I need to fold them together, I guess. I suppose this question applies to Free Monads in Cats in general, so I'll tag Cats as well. Thanks. You want to traverse List[ConnectionIO[Unit]] into ConnectionIO[List[Unit]] ? If so, that won't work: github.com/tpolecat/doobie/issues/465 – Yuval Itzchakov 2 hours ago List[ConnectionIO[Unit]] ConnectionIO[List[...

Generate a list of Tuple2 objects meeting some conditions

Image
Clash Royale CLAN TAG #URR8PPP Generate a list of Tuple2 objects meeting some conditions I want to generate a list of Tuple2 objects . Each tuple (a,b) in the list should meet the following 4 conditions: list Tuple2 objects (a,b) a b b>a a/b 1/30 a b Number N N BigInt How to write a scala function to generate the List of Tuples meeting the above requirements?( Even better if the a and b lies in a given interval (N1,N2) where N2>N1 instead of above 4th condition) scala function the List of Tuples a b interval (N1,N2) N2>N1 This is my attempt..may be it is fine for Ints and Longs..But for BigInt there is sqrt problem I am facing..Please correct if I am wrong in my approach in coding as below: scala> def genTups(N:Long) ={ | val x = for(s<- 1L to Math.sqrt(N).toLong) yield s*s; | val y = x.combinations(2).map{ case Vector(a,b) => (a,b)}.toList | y.filter(t=> (t._1*30/t._2)>=1) | } genTups: (N: Long)List[(Long, Long)] scala> genTu...

Object instantiation variants in scala

Image
Clash Royale CLAN TAG #URR8PPP Object instantiation variants in scala I am really new to scala, and I am currently making my way through the tour (https://docs.scala-lang.org/tour/variances.html). Now, looking at some library ( akka-http ), I stumbled across some code like this: akka-http def fetchItem(itemId: Long): Future[Option[Item]] = Future { orders.find(o => o.id == itemId) } And I don't quite understand the syntax, or more precisely, the = Future { part. As I learned, the syntax for methods is def [methodName]([Arguments])(:[returnType]) = [codeblock] . = Future { def [methodName]([Arguments])(:[returnType]) = [codeblock] However the above seems to differ in that its having the Future in front of the "codeblock". Is this some kind of object instantiation? Because I could not find documentation about this syntax, I tried in my play code stuff like this: Future { val myCat:Cat = new Cat("first cat") val myOtherCat:Cat = Cat { "seco...

join streaming and static dataframes does nothing

Image
Clash Royale CLAN TAG #URR8PPP join streaming and static dataframes does nothing So I'm trying to setup a stream from Kafka, and then add columns from a table to that dataframe based on a matching id in the kafka message and table. I've got two separate files, the first one calls a method in streamKafka_ASH to setup the stream and then it prints out the contents. val query = streamKafka_ASH.setupStream(spark, bootstrapservers,zkPath, topics, zkHosts, consumerGroup, batchIntervalSeconds.toInt, autoOffset, checkpointDir) .writeStream .outputMode("append") .format("console") .trigger(ProcessingTime(intervalMs = batchIntervalSeconds.toInt * 1000)) .start() query.awaitTermination() And here is the code in streamKafka_ASH.setupStream(...) val marketingTrackingSchema = new StructType() .add("id", StringType) .add("device", StringType) .add("type", StringType) .add(...

Call a method named `var` in Scala [duplicate]

Image
Clash Royale CLAN TAG #URR8PPP Call a method named `var` in Scala [duplicate] This question already has an answer here: I am using a third-part Java library, which defines a method named var . In Java, that is not a problem. In Scala, var is a reserved word and obj.var() gives a compilation error. var var obj.var() Is there a more elegant solution to this than obj.getClass().getMethod("var").invoke() ? obj.getClass().getMethod("var").invoke() This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. how about `var` with backticks? – Joel Berkeley 4 mins ago `var` Scala literal identifiers (backticks) – prayagupd 1 min a...

fruitless type test: a value of type Option[akka.actor.ActorSystem] cannot also be a akka.actor.ActorSystem

fruitless type test: a value of type Option[akka.actor.ActorSystem] cannot also be a akka.actor.ActorSystem I am using scapegoat for static code analysis i am getting a warning message fruitless type test: a value of type Option[akka.actor.ActorSystem] cannot also be a akka.actor.ActorSystem here is my code object ActorSystemSetting extends ActorSystemSettingTrait{ val config = ConfigFactory.load() val log = LoggerFactory.getLogger(this.getClass) var actorSystem : Option[ActorSystem] = None def createActorSystem: Option[ActorSystem] = { actorSystem = Option(ActorSystem("ArteciateActorSystem", config)) actorSystem } def getActorSystem : Option[ActorSystem] ={ if (actorSystem == None){ createActorSystem } else{ log.debug("ActorSystem is not null") } actorSystem } } In this section i am getting warning message on the line case Some(system: ActorSystem) => Option(ActorSystemSetting.getActorSystem) mat...

Scala playfamework - how to wrap one JSON string with another?

Scala playfamework - how to wrap one JSON string with another? I have JSON data coming from two different API endpoints. The first JSON contains data about stores and the second contains data on transactions(sales). For each store Id I'm getting an array of transactions and parsing it into JsValue . So I have a store Jsvalue representing the certain store and transactions JsValue, representing an array of transactions for the store. Then I stringify the JsValues: JsValue store transactions (Json.stringify(storeJsValue), Json.stringify(transactionsJson)) Printed result of the stringified JsValues for the above Array[(String, String)]: ({"store_id":"01","name":"Store_1"}, [{"saleId": 12, "name": "New name1", "saleType": "New Type1"]}, {"saleId": 222, "name": "Some name1", "saleType": "SomeType5"}) ({"store_id":"02","nam...