Quantcast
Channel: SCN : All Content - All Communities
Viewing all articles
Browse latest Browse all 3280

Julia, data analysis’s little sister...meets SAP HANA

$
0
0

d_shop_blog_logo.jpg

If you are an SAP Employee, please follow us on Jam.


Julia is not that young right now…as it first appeared on 2012 It is a high-level dynamic programming language designed to address the requirements of high-performance numerical and scientific computing while also being effective for general purpose programming.

 

Julia_Logo.png

Woaw! That was a big description…so why should we care? Well…maybe Julia was designed to be the language to rule them all…a language that can be used in any given situation…and without stopping to say if that’s true or not…I must say…Julia is really cool


So…no example or demonstration would be complete if we didn’t hook it up with SAP HANA, right? So…let’s go and do it -;)

 

First, we need to create a Calculation View and call it “FLIGHTS_BY_CARRIER”. It will be composed of two tables, SCARR and SFLIGHT.

 

First, we need to create a Join object and link the table by MANDT and CARRID. From here select the following fields as output MANDT, CARRID, CARRNAME, PRICE and CURRENCY.

 

Then create an Aggregation object selecting the fields CARRNAME, PRICE (As Aggregated Column) and CURRENCY. Filter the CURRENCY field by ‘USD’.

 

Then create a Projection object and select only PRICE and CARRNAME.


On the Semantics object make sure to select “CROSS CLIENT” as the Default Client.

 

Calculation_View.jpg

Now, switch to the SAP HANA Development View and create a new repository. Call it “Flights”.

 

Create a new “XS Engine” project and call it “Flights” as well. Link it to the “Flights” repository.

 

Create an empty “.xsapp” file.

 

Create a file called “.xsaccess” with the following code.

 

 

.xsaccess

{

"exposed" : true,

"authentication" : [ { "method" : "Basic" } ]

}

 

Finally create a file called “flights.xsodata” with the following code

 

flights.xsodata

service {

          "Blag/FLIGHTS_BY_CARRIER.calculationview"as"FLIGHTS"keysgeneratelocal"Id";

}


Activate your project and launch it on your browser, you should see something like this…


XSProject.jpg

The SAP HANA part is done…so we can move into the Julia part…

 

Go into your Julia environment and install the following packages

  • HTTPClient
  • Codecs
  • LightXML

 

You only need to do Pkg.add(“PackageName”) for each of them.


Then create a file called Julia_HANA_XML.jl on your favorite editor and copy the following code


 

Julia_HANA_XML.jl

using HTTPClient.HTTPC

using Codecs

using LightXML

 

credentials=encode(Base64,"SYSTEM:YourPassword")

Auth = bytestring(credentials)

Auth = "Basic " * Auth

 

flights=HTTPC.get("http://yourserver:8000/Flights/flights.xsodata/FLIGHTS",RequestOptions(headers=[("Authorization",Auth)]))

 

raw_text = takebuf_string(flights.body)

xdoc = parse_string(raw_text)

xroot = root(xdoc)

 

entry = get_elements_by_tagname(xroot,"entry")

 

for flights in entry

  print(content(find_element(find_element(find_element(flights,"content"),"properties"),"CARRNAME")),": ",

   content(find_element(find_element(find_element(flights,"content"),"properties"),"PRICE")),"\n")

end


To run this application, simply go to your Julia environment and type


Include(“Julia_HANA_XML.jl”)

 

Julia_HANA.jpg

 

If you are wondering…why didn’t I use JSON instead of XML? Well…there’s an easy explanation for that Somehow…the HTTPClient package have a problem using ?$format=json so I was forced to use XML instead…


Viewing all articles
Browse latest Browse all 3280

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>