Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@
target

# Properties files (may contain user credentials)
consumer.properties
producer.properties
cloud.properties

# Exercises folder
exercises/*
!exercises/exercise.sh
!exercises/exercise.bat
!exercises/README.md

/flink*

6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

## Version 0.1.0

* Initial commit of required files for a public repo.
* Initial commit of required files for a public repo.

## Version 0.2.0

* Initial commit of the exercise code.
59 changes: 58 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,60 @@
# Apache Flink Table API for Java

This repository is for the **Apache Flink Table API for Java** course provided by Confluent Developer.
This repository is for the **Apache Flink Table API for Java** course provided by Confluent Developer.

## A Simple Marketplace with Apache Flink

Throughout this course, we'll be executing a series of Flink queries focusing on an eCommerce Marketplace. Before you get started with the exercises, take a moment to familiarize yourself with the repository.

## Exercises

The course is broken down into several exercises. You will work on exercises in the `./exercises` folder.

### exercises/exercise.sh

The `exercise.sh` script is there to help you advance through the exercises.

The basic flow of an exercise is:

- `stage` the exercise (I.E. Import any new code necessary to begin the exercise).
- `solve` the exercise (Either manually, or using the `solve` command below).

You can list the exercises by running:

```bash
./exercise.sh list
```

You can stage an exercise by running:

```bash
./exercise.sh stage <exercise number>
```

You can automatically solve an exercise by running:

```bash
./exercise.sh solve <exercise number>
```

**WARNING:** Solving an exercise will overwrite your code.

You can solve a single file by running:

```bash
./exercise.sh solve <exercise number> <file name>
```

**NOTE:** We encourage you to solve the exercise yourself. If you get stuck, you can always look at the solution in the `solutions` folder (see below).

## Staging

The `staging` folder contains the files necessary to set up each exercise. These will be copied to the `exercises` folder when you execute the `stage` command with the `exercise.sh` script.

In general, you can ignore this folder.

## Solutions

The `solutions` folder contains complete solutions for each exercise. These will be copied to the `exercises` folder when you execute the `solve` command with the `exercise.sh` script.

In general, you can ignore this folder, but you might find it helpful to reference if you get stuck.
59 changes: 59 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

EXERCISES_DIR=exercises
SOLUTIONS_DIR=solutions
STAGING_DIR=staging

function help() {
echo "Usage:"
echo " build.sh <command>"
echo " Commands:"
echo " validate - Run through each exercise, stage the exercise, then apply the solution. Verify the exercise builds in it's final state."
}

function validate() {
WORKING_DIR=$(pwd)

EXERCISES=($(ls $SOLUTIONS_DIR/ | grep "^[0-9]*"))

TMP_DIR=target/tmp
rm -rf $TMP_DIR
mkdir -p $TMP_DIR

cp -r $EXERCISES_DIR $TMP_DIR
cp -r $SOLUTIONS_DIR $TMP_DIR
cp -r $STAGING_DIR $TMP_DIR

cd $TMP_DIR/$EXERCISES_DIR

for EXERCISE in "${EXERCISES[@]}"
do
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
echo $EXERCISE
./exercise.sh stage $EXERCISE
./exercise.sh solve $EXERCISE
echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"

if [ -f "pom.xml" ]; then
mvn clean test
fi
done

rm -rf $TMP_DIR

cd $WORKING_DIR
}

## Determine which command is being requested, and execute it.
COMMAND=${1:-"help"}
if [ "$COMMAND" = "validate" ]; then
validate
elif [ "$COMMAND" = "help" ]; then
help
else
echo "INVALID COMMAND: $COMMAND"
help
exit 1
fi
110 changes: 110 additions & 0 deletions exercises/exercise.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

EXERCISE_DIR=./
SOLUTIONS_DIR=../solutions
STAGING_DIR=../staging

if [ ! -d $STAGING_DIR ]; then
echo "$STAGING_DIR could not be found."
exit 1
fi

if [ ! -d $SOLUTIONS_DIR ]; then
echo "$SOLUTIONS_DIR could not be found."
exit 1
fi

function help() {
echo "Usage:"
echo " exercises.sh <Command>"
echo " Commands:"
echo " stage <Exercise Filter> - Setup the exercise."
echo " <Exercise Filter> - A portion of the exercise name (eg. the exercise number) that will be used to select the exercise."
echo " solve <Exercise Filter> <File Filter> - Solve the exercise."
echo " <Exercise Filter> - A portion of the exercise name (eg. the exercise number) that will be used to select the exercise."
echo " <File Filter> - (Optional) A portion of a file name that will be used to select while file to copy from the solution."
echo " list - List all exercises."
echo " Exercise Filter: A portion of the name of the exercise. Eg. The Exercise Number. If multiple matches are found, the first one will be chosen."
}

function stage() {
EXERCISE_FILTER=$1
MATCHED_EXERCISES=($(ls $STAGING_DIR | grep ".*$EXERCISE_FILTER.*"))
EXERCISE=${MATCHED_EXERCISES[0]}

echo "STAGING $EXERCISE"

cp -r $STAGING_DIR/$EXERCISE/. $EXERCISE_DIR
}

function solve() {
EXERCISE_FILTER=$1
FILE_FILTER=${2:-""}
MATCHED_EXERCISES=($(ls $SOLUTIONS_DIR | grep ".*$EXERCISE_FILTER.*"))
EXERCISE=${MATCHED_EXERCISES[0]}
SOLUTION=$SOLUTIONS_DIR/$EXERCISE

if [ -z $FILE_FILTER ]; then
echo "SOLVING $EXERCISE"

cp -r $SOLUTION/. $EXERCISE_DIR
else
WORKING_DIR=$(pwd)
cd $SOLUTION
MATCHED_FILES=($(find . -iname "*$FILE_FILTER*"))
cd $WORKING_DIR

if [ -z ${MATCHED_FILES:-""} ]; then
echo "FILE NOT FOUND: $FILE_FILTER"
exit 1
fi

FILE_PATH=${MATCHED_FILES[0]}

echo "COPYING $FILE_PATH FROM $EXERCISE"

cp $SOLUTION/$FILE_PATH $EXERCISE_DIR/$FILE_PATH
fi

}

function list() {
EXERCISES=$(ls $SOLUTIONS_DIR)

for ex in "${EXERCISES[@]}"
do
echo "$ex"
done
}

COMMAND=${1:-"help"}

## Determine which command is being requested, and execute it.
if [ "$COMMAND" = "stage" ]; then
EXERCISE_FILTER=${2:-""}
if [ -z $EXERCISE_FILTER ]; then
echo "MISSING EXERCISE ID"
help
exit 1
fi
stage $EXERCISE_FILTER
elif [ "$COMMAND" = "solve" ]; then
EXERCISE_FILTER=${2:-""}
FILE_FILTER=${3:-""}
if [ -z $EXERCISE_FILTER ]; then
echo "MISSING EXERCISE ID"
help
exit 1
fi
solve $EXERCISE_FILTER $FILE_FILTER
elif [ "$COMMAND" = "list" ]; then
list
elif [ "$COMMAND" = "help" ]; then
help
else
echo "INVALID COMMAND: $COMMAND"
help
exit 1
fi
Loading