This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PCollection<String> resultCollection = productCollection.apply(ParDo | |
.of(new DoFn<String, String>() { | |
@ProcessElement | |
public void process(ProcessContext processContext) { | |
double average = processContext.sideInput(averagePrice); | |
String strings = processContext.element(); | |
assert strings!= null; | |
String[] splits = strings.split(","); | |
double price = Double.parseDouble(splits[3].trim()); | |
if (price >= average) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Schema productTypeSchema = Schema.of(Schema.Field.of("ProductTypeId", Schema.FieldType.INT32), | |
Schema.Field.of("ProductType", Schema.FieldType.STRING) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PCollection<String> productCollection = | |
pipeline.apply(TextIO.read().from("/data/section1/products.csv")) | |
.apply("FilterHeader", Filter.by(line -> | |
!line.isEmpty() && !line.contains("ProductId, ProductName, ProductTypeId, Price")) | |
); | |
PCollection<KV<Integer, String>> productTypeCollection = | |
pipeline.apply(TextIO.read().from(productTypes)) | |
.apply("FilterHeader", Filter.by(line -> | |
!line.isEmpty() && !line.contains("ProductTypeId, ProductType"))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int linearSearch(int dataCollection[], int element) { | |
for (int index = 0; index < dataCollection.length; index++) { | |
if (dataCollection[index] == element) | |
return index; | |
} | |
return -1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int binarySearch(int dataCollection[], int element) { | |
int left = 0, right = dataCollection.length - 1; | |
while (left <= right) { | |
int mid = left + (right - left) / 2; | |
// Verify if element is present at mid | |
if (dataCollection[mid] == element) | |
return mid; | |
// If element greater, ignore left half |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyGraph | |
{ | |
private int vertices; | |
private LinkedList<Integer> adjacency[]; | |
MyGraph(int v) { | |
vertices = v; | |
adjacency = new LinkedList[v]; | |
for (int i=0; i<v; ++i) | |
adjacency[i] = new LinkedList(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyGraph { | |
private int vertices; | |
private LinkedList<Integer> adjacency[]; | |
MyGraph(int v) { | |
vertices = v; | |
adjacency = new LinkedList[v]; | |
for (int i = 0; i < v; ++i) | |
adjacency[i] = new LinkedList(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void bubbleSort(int dataCollection[]) | |
{ | |
int n = dataCollection.length; | |
for (int i = 0; i < n - 1; i++) | |
for (int j = 0; j < n - i - 1; j++) | |
if (dataCollection[j] > dataCollection[j + 1]) { | |
// swap arr[j+1] and arr[j] | |
int temp = dataCollection[j]; | |
dataCollection[j] = dataCollection[j + 1]; | |
dataCollection[j + 1] = temp; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void swap(int[] arr, int i, int j) { | |
int temp = arr[i]; | |
arr[i] = arr[j]; | |
arr[j] = temp; | |
} | |
static int partition(int[] arr, int low, int high) { | |
// Pick pivot | |
int pivot = arr[high]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void merge(int dataCollection[], int left, int mid, int right) { | |
// Find size of two sub arrays to be merged | |
int n1 = mid - left + 1; | |
int n2 = right - mid; | |
int leftTempArray[] = new int[n1]; | |
int rightTempArray[] = new int[n2]; | |
// Set data to temp arrays | |
for (int i = 0; i < n1; ++i) |
OlderNewer