Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 03:20
    Counterfly commented #1476
  • 03:20
    Counterfly commented #1476
  • 02:43
    thesamet commented #1476
  • 01:43
    Counterfly edited #1476
  • 01:42
    Counterfly edited #1476
  • 01:42
    Counterfly edited #1476
  • 01:42
    Counterfly edited #1476
  • 01:37
    Counterfly edited #1476
  • 01:36
    Counterfly synchronize #1476
  • 01:16
    Counterfly synchronize #1476
  • Jan 29 23:00

    mergify[bot] on master

    Update sbt-mdoc to 2.3.7 (#1479… (compare)

  • Jan 29 23:00
    mergify[bot] closed #1479
  • Jan 29 22:46
    mergify[bot] synchronize #1479
  • Jan 29 22:46
    mergify[bot] closed #1478
  • Jan 29 22:46

    mergify[bot] on master

    Update nscplugin, sbt-scala-nat… (compare)

  • Jan 29 22:31
    mergify[bot] synchronize #1478
  • Jan 29 22:29

    mergify[bot] on master

    Update mockito-core to 5.1.0 (#… (compare)

  • Jan 29 22:29
    mergify[bot] closed #1477
  • Jan 29 22:17
    mergify[bot] labeled #1479
  • Jan 29 22:17
    mergify[bot] assigned #1479
Nadav Samet
@thesamet
Hi @kyle.leeners_gitlab , when you generate Java code from the proto, the scalapb options will not affect it, and setting java-specific options won't affect the Scala source generation.
Kyle Leeners
@kyle.leeners_gitlab
awesome, thanks! I'll start to go down that road
Kyle Leeners
@kyle.leeners_gitlab

Hello, another question. I've got a proto file that I'd like to generate as both scala and java. The file imports another proto file (sourced though sbt). I'm running into issues during the generation because the imported file doesn't have any of the java conversion options.

Is there a way to add / decorate the java conversion options? I don't have direct access to the file, only the ability to import it.

Here's the file i'm trying to pull in for reference

syntax = "proto3";

import "scalapb/scalapb.proto";

option (scalapb.options) = {
  single_file: true
  lenses: true
  retain_source_code_info: true
  flat_package: true
  no_default_values_in_constructor: true,
  package_name: "foo"
};

message PackageUid {
  option (scalapb.message).extends = "bar";
  option (scalapb.message).companion_extends = "baz";

  string uid = 1;
}
Nadav Samet
@thesamet
@kyle.leeners_gitlab you can use package-scoped options to enable java_conversions for an entire package: https://scalapb.github.io/docs/customizations/#package-scoped-options - the option to set is java_conversions: true
Kyle Leeners
@kyle.leeners_gitlab
i dont have the ability to define a package name for the PackageUid.proto. Is there some default that i can hook into? Or would it just be foo?
Nadav Samet
@thesamet
@kyle.leeners_gitlab The thing is that if you don't have package or java_package in that file, the generated Java code doesn't have a package statement. I can't recall the details, but this leads to a problem where the generated Java code can't be accessed from Scala, adn there isn't much that can be done on the ScalaPB side for this.
Kyle Leeners
@kyle.leeners_gitlab
okay good to know. Maybe I can bug some people to add a package statement
Nadav Samet
@thesamet
sounds like a pretty reasonable thing to have.
Nadav Samet
@thesamet
@dkichler I wasn't able to reproduce the plugin resolution either on Linux nor Mac. I think it's a local issue. However, there were a number of issues with the build itself. I sent a PR https://github.com/dkichler/protoc-plugin-resolution-issue/pull/1/files with various comments explaining the issues.
1 reply
Matt Davis
@Matt-S6
hi! Is this the right place to ask a scalapb-sparksql usage question? In particular I'm looking for a way to understand some scala implicit resolution on a GeneratedMessage.
Nadav Samet
@thesamet
Hi @Matt-S6 , yes, this is the best place for these questions! :)
Matt Davis
@Matt-S6
Yay! ok, @thesamet, I got the sparksql-scalapb-test project to reproduce the issue. Here's the draft PR: thesamet/sparksql-scalapb-test#5
1 reply
Nadav Samet
@thesamet
@Matt-S6 Yes, you're really close. The error message tells you that you need to provide an implicit Encoder for your type. In L118, try adding a second implicit parameter, encoder: org.apache.spark.sql.Encoder[A].
Another way to write it, since you don't need direct access to the implicit values and they are just being passed through:
def fromRawEventDS[A <: GeneratedMessage : GeneratedMessageCompanion : Encoder](
    ds: Dataset[RawEvent]
  ) = ...
7 replies
João Ferreira
@jtjeferreira
Hi. I am an happy user of scalapb. Thanks for this amazing project. However recently I had the need to use java grpc in another project and was really frustrated I could not find how to define custom types like in scalapb as described here https://scalapb.github.io/docs/customizations#custom-types. By luck, do you know if this a feature is available in Java? Or only scalapb implements this and it is not common in other languages? Or my google skills are failing me?
Nadav Samet
@thesamet
Hey @jtjeferreira , sorry have missed your question from last week - thanks for the feedback! Custom types is a unique feature of ScalaPB. The standard implementations do not offer this flexibility.
João Ferreira
@jtjeferreira
Thanks @thesamet
Vénérée Randrianarisoa
@Maia1003_gitlab

Hi everyone,
I am new to ScalaPB and started by using the tutorial by downloading the project from github: https://scalapb.github.io/docs/getting-started.

I managed to generate the codes after sbt compile in:
target/scala-2.13/src_managed/main/scalapb/com/example/tutorial/addressbook

My main question is how to use the generated codes (case classes for each message) obtained after compiling since they are in ..\target\scala-2.13\src_managed\main\scalapb\tutorial\addressbook\

Also, in the codes from github, there is no tutorial package in /scr/main/scala/: I tried to refactor and create a tutorial package as
\basic\src\main\scala\tutorial\AddressBookMain.scala but I got the same errors: Person and AddressBook are not found (cannot resolve symbol AddressBook and Person).

Coud someone help me with those please, I am really stuck with this (I use IntelliJ IDEA)
Thank you very much,
Best regards.
Maia

Nadav Samet
@thesamet
Hi @natevecc , can you try compiling and running your project in SBT outside IntelliJ? If this works, then try re-importing your project into IntelliJ. If it doesn't work, then let's look into the project structure.
Vénérée Randrianarisoa
@Maia1003_gitlab
The project structure is as follows: the generated codes are in C:\ScalaPBBasic\basic\target\scala-2.13\src_managed\main\scalapb\tutorial\addressbook
And yes it compiles outside of IntelliJ
Hi @thesamet : you are right, after following your advices, it works ! THANKS A LOT ! What is the problem with IntelliJ ?
Also I don't understand that codes in target folder can be used back in the scala main sources (new to Scala as well).
Nadav Samet
@thesamet
@Maia1003_gitlab , sometimes intellij doesn't detect when additional source directories get added to the projects, and then re-importing helps. Now that they are in, it should keep working.
ScalaPB generates sources under a different subdirectory (target/.../src-managed) so they don't get mixed up with your source code, and also so you don't edit them, or check them in source control.
SBT has a list of source directories to use, target/.../src_managed is one of them. If you type in sbt sourceDirectories it will print out this list.
Vénérée Randrianarisoa
@Maia1003_gitlab
@thesamet , thanks a lot !
Vénérée Randrianarisoa
@Maia1003_gitlab

Hi commnunity, I try to implement a server with ScalaPB by following this: https://medium.com/rahasak/reactive-microservices-with-grpc-and-scala-e4767ca2d34a. I got a red highligted error on build() , on server != null, and awaitTermination() is not recognized :val server = ServerBuilder
.forPort(9000)
.addService(ProtoReflectionService.newInstance())
.addService(DocumentServiceGrpc.bindService(new DocumentServiceImpl, ExecutionContext.global))
.build()
.start()

// block until shutdown
if (server != null) {
server.awaitTermination()
}

Have someone an up-to-date simple server example, please and see what is problem with this codes? Thank you. Best,
Nadav Samet
@thesamet
If you ignore the red highlight (potential IntelliJ bug), does it work in sbt?
Vénérée Randrianarisoa
@Maia1003_gitlab
@thesamet yes it is working with the red highlight as well (weird that it compiles without error)
Nadav Samet
@thesamet
I think I've seen this before. It's an IntelliJ bug, you are doing nothing wrong. Possibly one way to overcome it is to specify the type of the server val, explicitly.
so something like val server: Server = ...
Vénérée Randrianarisoa
@Maia1003_gitlab
after adding the type, it's still red
Nadav Samet
@thesamet
what's the error?
Vénérée Randrianarisoa
@Maia1003_gitlab
I don't have error: build() is just in red
and awaitTermination is not recognized
It'll be interestring to have a tutorial for server-client in ScalaPB tutorial...
Nadav Samet
@thesamet
If it can't be fixed by adding a type annotation, I suggest to just ignore it.
Vénérée Randrianarisoa
@Maia1003_gitlab
OK, right, I did't see that ! Thank you !
Vénérée Randrianarisoa
@Maia1003_gitlab
On https://github.com/xuwei-k/grpc-scala-sample/tree/master/grpc-scala/src/main/scala/io/grpc/examples/helloworld: the client and the server apps are in the same project: as far as I understand, the server must be running while lauching a client app: how can I have the two apps running in parallel with the two apps (I use IntelliJ IDEA and run each app by Run ... ? Thank you
Nadav Samet
@thesamet
I haven't used IntelliJ for a while. Isn't it possible to run two apps at the same time?
If not, you can run one of them from SBT
Vénérée Randrianarisoa
@Maia1003_gitlab
Ok, thank you
just curious: what IDE do you use (I am on Windows + IntelliJ)
Nadav Samet
@thesamet
VS Code
Vénérée Randrianarisoa
@Maia1003_gitlab
ok thank you
Nadav Samet
@thesamet
I do always have SBT open in a terminal next to the IDE, and run tests in there while developing.