Last active
December 18, 2015 14:29
-
-
Save nathanlws/5797500 to your computer and use it in GitHub Desktop.
Revisions
-
nathanlws revised this gist
Oct 8, 2013 . 1 changed file with 6 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,9 @@ // // See: https://github.com/foundationdb/sql-parser // import com.foundationdb.sql.parser.*; import com.foundationdb.sql.parser.SQLParserContext.*; public class CustomCase { public static class ColumnNamePrinter implements Visitor { -
nathanlws revised this gist
Jun 17, 2013 . 1 changed file with 7 additions and 27 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,36 +1,14 @@ import com.akiban.sql.parser.*; import com.akiban.sql.parser.SQLParserContext.*; public class CustomCase { public static class ColumnNamePrinter implements Visitor { @Override public Visitable visit(Visitable visitable) { QueryTreeNode node = (QueryTreeNode)visitable; if(node.getNodeType() == NodeTypes.COLUMN_REFERENCE) { ColumnReference ref = (ColumnReference)node; System.out.println(" " + ref.getColumnName()); } return visitable; } @@ -58,13 +36,15 @@ public IdentifierCase getIdentifierCase() { } public static void main(String[] args) throws Exception { if(args.length != 1) { System.err.println("Expected query argument"); System.exit(1); } final String s = args[0]; CustomSQLParser parser = new CustomSQLParser(); ColumnNamePrinter printer = new ColumnNamePrinter(); for(IdentifierCase c : IdentifierCase.values()) { System.out.println(c); parser.setIdentifierCase(c); StatementNode stmt = parser.parseStatement(s); stmt.accept(new ColumnNamePrinter()); -
nathanlws revised this gist
Jun 17, 2013 . 1 changed file with 22 additions and 20 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,28 @@ import com.akiban.sql.parser.*; import com.akiban.sql.parser.SQLParserContext.*; /** * Demonstration of how to get custom identifier case behavior. * * Compiling and running: * $ javac CustomCase.java * $ java CustomCase * IdentifierCase: UPPER * QWER * ASDF * ZXCV * jKlM * IdentifierCase: LOWER * qwer * asdf * zxcv * jKlM * IdentifierCase: PRESERVE * qwer * aSdF * ZXCV * jKlM */ public class CustomCase { public static class ColumnNamePrinter implements Visitor { @Override @@ -49,23 +71,3 @@ public static void main(String[] args) throws Exception { } } } -
nathanlws renamed this gist
Jun 17, 2013 . 1 changed file with 3 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ import com.akiban.sql.parser.*; import com.akiban.sql.parser.SQLParserContext.*; public class CustomCase { public static class ColumnNamePrinter implements Visitor { @Override public Visitable visit(Visitable visitable) { @@ -23,7 +23,6 @@ public Visitable visit(Visitable visitable) { public boolean skipChildren(Visitable node) { return false; } } public static class CustomSQLParser extends SQLParser { private IdentifierCase identCase = IdentifierCase.PRESERVE; @@ -36,7 +35,6 @@ public IdentifierCase getIdentifierCase() { } } public static void main(String[] args) throws Exception { final String s = "SELECT qwer, aSdF, ZXCV, \"jKlM\" FROM t"; @@ -53,7 +51,8 @@ public static void main(String[] args) throws Exception { } /* $ javac CustomCase.java $ java CustomCase IdentifierCase: UPPER QWER ASDF -
nathanlws created this gist
Jun 17, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,72 @@ import com.akiban.sql.parser.*; import com.akiban.sql.parser.SQLParserContext.*; public class Quick { public static class ColumnNamePrinter implements Visitor { @Override public Visitable visit(Visitable visitable) { QueryTreeNode node = (QueryTreeNode)visitable; if(node.getNodeType() == NodeTypes.COLUMN_REFERENCE) { ColumnReference ref = (ColumnReference)node; System.out.println(ref.getColumnName()); } return visitable; } @Override public boolean visitChildrenFirst(Visitable node) { return false; } @Override public boolean stopTraversal() { return false; } @Override public boolean skipChildren(Visitable node) { return false; } } public static class CustomSQLParser extends SQLParser { private IdentifierCase identCase = IdentifierCase.PRESERVE; public void setIdentifierCase(IdentifierCase newCase) { identCase = newCase; } public IdentifierCase getIdentifierCase() { return identCase; } } public static void main(String[] args) throws Exception { final String s = "SELECT qwer, aSdF, ZXCV, \"jKlM\" FROM t"; CustomSQLParser parser = new CustomSQLParser(); ColumnNamePrinter printer = new ColumnNamePrinter(); for(IdentifierCase c : IdentifierCase.values()) { System.out.println("IdentifierCase: " + c); parser.setIdentifierCase(c); StatementNode stmt = parser.parseStatement(s); stmt.accept(new ColumnNamePrinter()); } } } /* Running prints: IdentifierCase: UPPER QWER ASDF ZXCV jKlM IdentifierCase: LOWER qwer asdf zxcv jKlM IdentifierCase: PRESERVE qwer aSdF ZXCV jKlM */