0

Have anyone tried this code before?

XmlSource<String> source = XmlSource.<String>from("gs://balajee_test/sample_3.xml")
              .withRootElement("book")
              .withRecordElement("author")
              .withRecordElement("title")
              .withRecordElement("genre")
              .withRecordElement("price")
              .withRecordElement("description")
              .withRecordClass(XMLFormatter.class);

PCollection<String> output = p.apply(Read.from(source));

https://beam.apache.org/documentation/sdks/javadoc/0.4.0/org/apache/beam/sdk/io/XmlSource.html

org.apache.beam.sdk.io.xml.XmlSource

Hope I'm using the correct 'XmlSource' class but still not able to resolve dependencies for method 'from("gs://balajee_test/sample_3.xml")' and getting compilation error for the same. The error message is :

The method from(String) is undefined for the type XmlSource

This question may go too silly but I really need to get it resolved in order to be able to read XML File stored in GCS Bucket.

Balajee Venkatesh
  • 1,041
  • 2
  • 18
  • 39
  • What version of the SDK are you using? Those documents are for a very old version (.4). The current version is 2.1. If you are using a newer version of the SDK, you want this: https://beam.apache.org/documentation/sdks/javadoc/2.1.0/ Also, you have two 'froms' with the same name as well. Is that intended? Could be the issue if you are on an old SDK. – Lara Schmidt Aug 30 '17 at 17:44
  • I'm sorry. Those two 'froms' were not intended. While posting this query by mistake I copied the same 'from' statement twice. I'm using 2.0 version. Is this the issue? – Balajee Venkatesh Aug 30 '17 at 18:18
  • Yeah, the API for XML Source has changed for the 2.0 version. I'd try using the new documentation for that specific version. https://beam.apache.org/documentation/sdks/javadoc/2.0.0/ You can see the XML Source by looking for org.apache.beam.sdk.io.xml – Lara Schmidt Aug 30 '17 at 20:27

1 Answers1

0

From comments, seem that the SDK used is 2.0 which has a new way to define a read from XML. Check the new documentation for how to read.

SDK IO documentation (for 2.0.0) can be found here: beam.apache.org/documentation/sdks/javadoc/2.0.0

Lara Schmidt
  • 309
  • 2
  • 6
  • Hi Lara, I thought this way would come in rescue as the link you referred has already put me into trouble. The code is running successfully but I don't why the values for corresponding XML elements are not getting mapped and I'm getting 'null' as all the component values. Please follow the link for more details : https://stackoverflow.com/questions/45933068/unable-to-read-xml-file-stored-in-gcs-bucket – Balajee Venkatesh Aug 30 '17 at 21:30
  • This is another question, right? Separate from this issue of not building? – Lara Schmidt Aug 31 '17 at 01:03
  • Exactly !!! This is the question on the solution you have given to me. I already tried that and facing the mentioned issues. Request you to look into that and get me some recommendations to resolve the 'null' value issues. – Balajee Venkatesh Aug 31 '17 at 01:48