Quantcast
Channel: Languages – AMIS Technology Blog | Oracle – Microsoft Azure
Viewing all 163 articles
Browse latest View live

Graph Database style explorations of relational database with Formula One data– Oracle Database 23c Property Graph

$
0
0
Read Time:3 Minute, 33 Second

The core Formula One data could be represented in a graph like this:

image

Drivers compete in races that are hosted on circuits. A result is achieved by the driver (position and points for the championship).

If this is the graph, some questions can easily be answered:

With whom has a specific driver (say Max Verstappen) shared the podium?

MATCH (a IS driver where a.name = ‘Max Verstappen’) -[b IS result where b.position <= 3]-> (c IS race) <-[d is result where d.position <= 3]- (e IS driver) 
WHERE NOT VERTEX_EQUAL(a,e)

Which drivers from the same country have shared the podium?

MATCH (a IS driver ) -[b IS result where b.position <= 3]-> (c IS race) <-[d is result where d.position <= 3]- (e IS driver) 
WHERE NOT VERTEX_EQUAL(a,e) and a.nationality = e.nationality

Lucky day: who won two or more races on the same day in the year (different years obviously)?

MATCH (a IS driver ) -[b IS result where b.position = 1]-> (c IS race)
  ,     (a IS driver ) -[d IS result where d.position = 1]-> (e IS race)
WHERE NOT VERTEX_EQUAL(c,e) and to_char(c.race_date,’DDMM’) = to_char(e.race_date,’DDMM’)

There are many more questions that can be answered using graph patterns in a graph pattern matching query. Patterns that are often more intuitive – easier to write, understand, debug and maintain – than their pure SQL equivalents. Of course the questions answered here can be answered using SQL as well – but these statements may not be as straightforward.

The formula one data is available to me (and you: see how in this article that allows you to fire up an Oracle Database 23c Free instance in a Gitpod workspace with a single click) in a relational database schema – 14 tables:

image

I have create a SQL Property Graph on top of a subset of these tables. That can be visualized like this:image

The SQL statement I used to create the property graph:

image

This statement defines the three vertex-tables (driver, race, circuit) and the two edge tables (results, hostings). It uses the relational tables drivers, races, results and circuits to draw the data from. Edge table hostings is a little bit special: it is based on table races that is also used to define the vertex table races. This edge table defines the link from races to circuits. This link is implemented in the relational schema through the foreign key (column) circuitid. This means that every record in table races produces a vertex entry (race) and an edge (hosted_by).

Using this property graph, the questions posed earlier in this article can easily be answered:

With whom has a specific driver (say Max Verstappen) shared the podium?

image

If you want to know how often he was on the podium with a specific other driver:

image

image

Which drivers from the same country have shared the podium?

image

Zooming in: which nationalities have ever had two or more drivers on the podium?image

Lucky day: who won two or more races on the same day in the year (different years obviously)?

image

Property Graph can help make seemingly complex questions – when approached relationally – become fairly straightforward. SQL Property Graph allows us to combine the two approaches – to refine or enrich the result from the property graph query or even combine multiple query results. I expect t0 be working on this more frequently because I like this approach. I would like to learn how well it scales.

And, as I mentioned, I am hoping for SQL Property Graphs to support Views as underpinning for edge and vertex tables in addition to tables and materialized views.

Resources

Source for this article: https://github.com/lucasjellema/gitpod-oracle-database-23c-free/blob/main/explorations/formula-one-sql-property-graph.sql.

Oracle Database 23c Documentation on SQL Property Graph: https://docs.oracle.com/en/database/oracle/property-graph/23.1/spgdg/getting-started-oracle-property-graphs.html

GitHub Repo with sources for this article: https://github.com/lucasjellema/gitpod-oracle-database-23c-free.

Oracle Database 23c Free environment with the Formular One data schema can be started using a Gitpod workspace definition. Read about it in this article .


Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

The post Graph Database style explorations of relational database with Formula One data– Oracle Database 23c Property Graph appeared first on AMIS, Data Driven Blog - Oracle & Microsoft Azure.


The Art of Programming– The Advent of Code Programming Puzzle Marathon

$
0
0

Just over three weeks ago, a colleague told me about The Advent of Code 2023. She explained how for 8 years every year in days and weeks leading up to Christmas every day a puzzle is released. A puzzle that you probably can only solve by making use of programming. How you implement your solution, using which language, tools, algorithms and other tricks is up to you. You submit the answer – usually a large number – and learn if it is correct. If it is, you get awarded a silver start and you receive a second assignment – typically somewhat harder than the first one. Solve that one, and a correct answer earns you a gold star. For 25 consecutive days, stars can be won.

I liked this idea and also my colleague’s suggestion that we organize a competition within our Conclusion ecosystem – of 30+ companies and close to 2800 colleagues. Not all of them programmers, but still a good number of potential participants. I decided on a few prizes for the top-performers ( and a cake bonanza for the winning team) and invited colleagues to join in. The lead time was very short (two days). Still, over 70 colleagues signed up and started earning stars over the next few days. We set up a Teams environment for sharing frustrations and epiphanies and the odd tip (and admiration).

The initial puzzles were somewhat challenging but certainly doable. Since the time of submission plays a role in awarding points and I am an early riser, for the first few days I was in the top 5 of our organization’s leaderboard. Was I going to win a prize I had awarded myself? That did not feel quite right.image

I need not have worried:after a week or so, the complexity of the puzzles started to increase. I lost momentum. A number of colleagues emerged as the toughest, disciplined competitors and the most versatile programmers. We ran into each other in the office and discussed today’s challenge. And earlier, mind boggling, brain cracking assignments.

I was and am impressed by how programming seemed to take off to the next level. In our regular work, sure we have to program. We develop solutions that satisfy functional requirements and of course fit within the non-functional boundaries. But the challenge is usually more in understanding the user’s wishes and the functional objectives than in cracking very complex programming nuts. But these puzzles in their misleading simplicity, devoid of the regular web of dependencies and limitations, brought out the real programming skills. Colleagues started applying patterns and algorithms that were needed, not just for finding an elegant solution but also a solution that would be produced within a few seconds. The naive, brute force method in many cases only produced an answer after hours of processing – or not at all. Shoelace algorithm, priority queue, Dijkstra’s algorithm, Bellman Ford, Kadane. A largely new world of simple, elegant, brilliant approaches to deceptively simple challenges was unveiled. It is almost like walking into a  museum and seeing a series of master paintings for the first time. Wow, that such a thing exists.

Programming at this level is craft or even an art that I do not (yet) master. I am in awe of my colleagues who do. Last night, we gathered with a dozen competitors to discuss our solutions to some of the earlier puzzles. What approach was selected – and how was it then applied? What caused the breakthrough – untied the knot? What were corner cases that needed to be dealt with. What programming language and tool was used? What does the actual code look like? And in some cases, nice anecdotes were shared, frequently dating back to university, homework assignments and exams. Occasionally to work situations where a similar challenge needed to be addressed.

In general, there seem to be three stages

1. Analyze Requirement: Read, analyze the puzzle. What is the objective [of the puzzle] , what is desired of us. What are constraints, what do we need to take into account?

2. Devise the approach, pick and shape the algorithm, visually and in pseudocode, using patterns

3,. Implement the code – pick a programming language (we have seen at least these languages and tools: Excel, Bash, Java, Python, C++, TypeScript, JavaScript/Node, C#, Rust, Google Sheets, Mendix), write the code, test it, and run it for real

Then submit the solution, get the feedback and perhaps return to the drawing board. Did we misunderstand the assignment? Miss an edge case? Mess up the input?

We will know the winners of The Advent of Code 2023 Conclusion Leaderboard at midnight on New Year’s Eve. I already know that I have several colleagues who are not merely good software engineers and valued application developers but who are really very good programmers – artists in their own right. Who revel in tough challenges and finding smart solutions by combining well known patterns and algorithms that fit the problem and implementing them in elegant, well performing code.

image

I am hoping to organize our own Conclusion Code Competition in the Spring of 2023 – where teams from the Conclusion companies compete as well as individual colleagues, customer teams and teams from  various universities. Sure, for prizes, But primarily for fun and the discovery of this wonderful art of pure programming.

Resources

25 algorithms every programmer should know – https://medium.com/techie-delight/top-25-algorithms-every-programmer-should-know-373246b4881b

10 algorithms we should know – https://dev.to/codesphere/10-algorithms-every-developer-should-learn-3lnm

Find majority element – elegant! – https://www.techiedelight.com/find-majority-element-in-an-array-boyer-moore-majority-vote-algorithm/

Processing – https://processing.org/ – a flexible software sketchbook and a language for learning how to code and to teach programming fundamentals within a visual context, Processing has also evolved into a development tool for professionals.. (used by one colleague, to also visualize some aspects of the puzzles)


The post The Art of Programming– The Advent of Code Programming Puzzle Marathon appeared first on AMIS Technology Blog | Oracle - Microsoft Azure.

Github Copilot getting started, a practical developer guide

$
0
0
github copilot

GitHub Copilot has captured the attention of developers worldwide, promising a revolutionary shift in the way we write code. While the concept sounds enticing, many developers are left wondering, “How do I actually use it in my programming workflow?” In this practical guide, we’ll explore step-by-step instructions on integrating GitHub Copilot into your coding journey.

Setting Up GitHub Copilot:

a. Installation: Begin by installing GitHub Copilot as an extension in your code editor such as Visual Studio Code.

b. Authentication: Link your GitHub account to enable Copilot and access its features seamlessly. After installing the extension VScode will ask you to sign in to your account. Make sure your account is subscripted to one of the available plans.

Make it work!

Let’s start with the basics. How do I get my copilot to do anything? The most basic hotkey we can use is ctrl + i. With this command we open a prompt window where we can interact directly with the copilot. Github Copilot getting started, a practical developer guide hello world

We can use this prompt window to ask our copilot to do anything, however we can quickly specify the direction of our prompt by using shortcuts like: /fix /doc /explain. We can use these commands to quickly interact with our copilot without having to write exhaustive prompts.

Write my documentation please

Sooo let’s apply what we have learned so far by making our copilot write some documentation for our hello world function app. We start by selecting the code we want to document, we press our hotkey ctrl + i and we write in our prompt “/doc include js doc types”. This will result in the copilot generating a suggestion which we can then accept by pressing the accept button. By supplying additional information in our prompt we can make the documentation the copilot will come up with more specific. To do this you can simple extend your prompt and press enter and the copilot will come up with new documentation. We have now succesfully made our copilot write documentation for our code.

Github Copilot getting started, a practical developer guide hello docs 1

In summary, GitHub Copilot presents a practical solution for developers seeking to streamline their coding process. Its AI-powered suggestions offer valuable assistance in generating code efficiently, facilitating additional features like documentation generation and improving productivity. By incorporating Copilot into their workflow, developers can benefit from its capabilities to expedite project development while maintaining code quality. As we continue to explore its potential, GitHub Copilot stands as a valuable tool in the arsenal of modern developers.

The post Github Copilot getting started, a practical developer guide appeared first on AMIS Technology Blog | Oracle - Microsoft Azure.

Viewing all 163 articles
Browse latest View live