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
anuvrat$ brew install go | |
==> Downloading https://homebrew.bintray.com/bottles/go-1.7.3.sierra.bottle.tar.gz | |
######################################################################## 100.0% | |
==> Pouring go-1.7.3.sierra.bottle.tar.gz | |
==> Caveats | |
As of go 1.2, a valid GOPATH is required to use the `go get` command: | |
https://golang.org/doc/code.html#GOPATH | |
You may wish to add the GOROOT-based install location to your PATH: |
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
Person(name=Alice, country=US, emailAddress=alice@abc.com) | |
Person(name=Bob, country=DE, emailAddress=bob@abc.com) | |
Person(name=Bob, country=DE, emailAddress=null) | |
Exception in thread "main" receipes.lambda.PersonNotFoundException | |
at receipes.lambda.FileToPOJO$$Lambda$22/1768305536.get(Unknown Source) | |
at java.util.Optional.orElseThrow(Optional.java:290) | |
at receipes.lambda.FileToPOJO.parsePerson(FileToPOJO.java:66) | |
at receipes.lambda.FileToPOJO.main(FileToPOJO.java:39) | |
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) | |
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) |
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
public static void main(String args[]) { | |
final List<String> test1 = Lists.newArrayList(" name : Alice", | |
"country: US", | |
"email:alice@abc.com"); | |
System.out.println(parsePerson(test1)); | |
final List<String> test2 = Lists.newArrayList(" name : Bob", | |
" locale: de_DE", | |
"email:bob@abc.com"); |
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
/** | |
* This method extracts the country information from the parsed lines. We first check if COUNTRY is present in the | |
* provided map. If not, we check if LOCALE is present. | |
* <br><br> | |
* In the case of LOCALE we process the string and try to extract the country code from it. | |
* | |
* @param values The values parsed from the list of lines. | |
* | |
* @return The Optional country object, which is present of if the values map contains COUNTRY or LOCALE key. | |
*/ |
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
/** | |
* Parse the lines to extract relevant attributes. | |
* <ul> | |
* <li>Each line contains only 1 value as key:value</li> | |
* <li>We are only interested in the attributes that are present in the Attribute enum.</li> | |
* <li>Name and Country must be present otherwise we'll throw PersonNotFoundException.</li> | |
* <li>These lines may not have all the attributes. For the missing attributes we'll set the value to NULL</li> | |
* <li>These lines may contain extra attributes that we are not interested in. Those should be ignored.</li> | |
* </ul> | |
* |
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
@Getter | |
@RequiredArgsConstructor | |
public enum Attribute { | |
NAME("name"), | |
COUNTRY("country"), | |
LOCALE("locale"), | |
EMAIL_ADDRESS("email"); | |
private final String key; |
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
@Getter | |
@RequiredArgsConstructor | |
public enum Country { | |
US("US"), | |
CA("CA"), | |
GB("GB"), | |
DE("DE"); | |
private final String key; | |
} |
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
@Value | |
public class Person { | |
private final String name; | |
private final Country country; | |
private final String emailAddress; | |
} |
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
CREATE EXTERNAL TABLE orders ( | |
order_id string, | |
item_id string, | |
quantity int, | |
checkout_price double, | |
address_id string | |
) PARTITIONED BY (orderDate string) | |
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n' | |
STORED AS TEXTFILE | |
LOCATION '/tables/orders/us'; |
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
select | |
trim(pgdb.datname) as Database, | |
trim(pgn.nspname) as Schema, | |
trim(a.name) as Table, | |
b.mbytes, | |
a.rows | |
from ( | |
select db_id, id, name, sum(rows) as rows | |
from stv_tbl_perm a | |
group by db_id, id, name |