Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

What am I doing wrong? #35

Closed
d0nski opened this issue Oct 4, 2016 · 3 comments
Closed

What am I doing wrong? #35

d0nski opened this issue Oct 4, 2016 · 3 comments

Comments

@d0nski
Copy link

d0nski commented Oct 4, 2016

Sorry if this is not the appropriate forum, but I have some questions surrounding your library that Im really struggling with - I'm new to Avro and Scala so forgive me if I'm missing the obvious.

I have a simple Avro Schema Asof.avsc generated by another system for me to supply them avro files in this schema. My assumption from reading your docs, would be to use something along the lines of whats shown in AvroTypeProviderExample. But when I do that, get compile errors.

Asof.avsc:

{
  "type" : "record",
  "name" : "Asof",
  "namespace" : "risk",
  "fields" : [ {
    "name" : "value",
    "type" : "string"
  } ]
}

my code:

package risk

import com.julianpeeters.avro.annotations._
import org.apache.avro.specific._
import org.apache.avro.generic._
import org.apache.avro.file._
import java.io.File


@AvroTypeProvider("src/main/avro/Asof.avsc")
@AvroRecord
case class Asof()



object AvroConverter extends App {
  println(Asof)
  val record = Asof("20160912")//compile error too many arguments to method apply


  val file = File.createTempFile("AsofTest", "avro")
  file.deleteOnExit()


  val userDatumWriter = new SpecificDatumWriter[Asof]
  val dataFileWriter = new DataFileWriter[Asof](userDatumWriter)
  dataFileWriter.create(record.getSchema(), file);//compile error cannot resolve symbol getSchema
  dataFileWriter.append(record);
  dataFileWriter.close();


  val schema = new DataFileReader(file, new GenericDatumReader[GenericRecord]).getSchema
  val userDatumReader = new SpecificDatumReader[Asof](schema)
  val dataFileReader = new DataFileReader[Asof](file, userDatumReader)
  val sameRecord = dataFileReader.next()


  println("deserialized record is the same as a new record based on the schema in the file?: " + (sameRecord == record) )


}

I'm using scala 2.10 and appropriate version on your lib with that - can you please advise what I am doing wrong here?

@julianpeeters
Copy link
Owner

That error suggests that the macro is not expanding, but I can't see why that would be. What does your build file look like? Are you using an IDE? I've not personally tested this in IDEs, and I hear that sometimes they have trouble with macros, but kinda just guessing here.

@d0nski
Copy link
Author

d0nski commented Oct 5, 2016

Hi Julian - thanks for the response. I am using Intellij with Maven. Build and dependencies are below:

<build>
        <plugins>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>3.2.1</version>
                <configuration>
                    <compilerPlugins>
                        <compilerPlugin>
                            <groupId>org.scala-lang.plugins</groupId>
                            <artifactId>macro-paradise_2.10</artifactId>
                            <version>2.1.0</version>
                        </compilerPlugin>
                    </compilerPlugins>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>compile</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

<dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.10</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.julianpeeters</groupId>
            <artifactId>avro-scala-macro-annotations_2.10</artifactId>
            <version>0.4.9</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.6</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.scalatest</groupId>
            <artifactId>scalatest_2.10</artifactId>
            <version>2.2.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

@d0nski
Copy link
Author

d0nski commented Oct 5, 2016

Look to have solved this by deleting all my scala libraries from maven repository and re-importing them. The code compiles now but Intellij just still mark them red.

@d0nski d0nski closed this as completed Oct 5, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants