Last active
December 12, 2015 08:59
-
-
Save ceteri/4747794 to your computer and use it in GitHub Desktop.
ANSI SQL in Cascading
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
$ gradle clean jar | |
$ hadoop jar build/libs/lingual-examples–1.0.0-wip-dev.jar | |
CUST_ID=100; PROD_ID=10; EMPID=100; NAME=Bill | |
CUST_ID=150; PROD_ID=20; EMPID=150; NAME=Sebastian |
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
import java.sql.Connection; | |
import java.sql.DriverManager; | |
import java.sql.ResultSet; | |
import java.sql.SQLException; | |
import java.sql.Statement; | |
public class JdbcExample | |
{ | |
public static void main( String[] args ) throws Exception | |
{ | |
new JdbcExample().run(); | |
} | |
public void run() throws ClassNotFoundException, SQLException | |
{ | |
Class.forName( "cascading.lingual.jdbc.Driver" ); | |
Connection connection = | |
DriverManager.getConnection( "jdbc:lingual:local;schemas=src/main/resources/data/example" ); | |
Statement statement = connection.createStatement(); | |
ResultSet resultSet = statement.executeQuery( | |
"select *\n" | |
+ "from \"EXAMPLE\".\"SALES_FACT_1997\" as s\n" | |
+ "join \"EXAMPLE\".\"EMPLOYEE\" as e\n" | |
+ "on e.\"EMPID\" = s.\"CUST_ID\"" ); | |
while( resultSet.next() ) | |
{ | |
int n = resultSet.getMetaData().getColumnCount(); | |
StringBuilder builder = new StringBuilder(); | |
for( int i = 1; i <= n; i++ ) | |
{ | |
builder.append( | |
( i > 1 ? "; " : "" ) | |
+ resultSet.getMetaData().getColumnLabel( i ) | |
+ "=" | |
+ resultSet.getObject( i ) ); | |
} | |
System.out.println( builder ); | |
} | |
resultSet.close(); | |
statement.close(); | |
connection.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment