Java Code Examples for org.apache.calcite.util.SourceStringReader

The following examples show how to use org.apache.calcite.util.SourceStringReader. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: flink   Source File: CalciteParser.java    License: Apache License 2.0 7 votes vote down vote up
/**
 * Equivalent to {@link SqlParser#create(Reader, SqlParser.Config)}. The only
 * difference is we do not wrap the {@link FlinkSqlParserImpl} with {@link SqlParser}.
 *
 * <p>It is so that we can access specific parsing methods not accessible through the {@code SqlParser}.
 */
private FlinkSqlParserImpl createFlinkParser(String expr) {
	SourceStringReader reader = new SourceStringReader(expr);
	FlinkSqlParserImpl parser = (FlinkSqlParserImpl) config.parserFactory().getParser(reader);
	parser.setTabSize(1);
	parser.setQuotedCasing(config.quotedCasing());
	parser.setUnquotedCasing(config.unquotedCasing());
	parser.setIdentifierMaxLength(config.identifierMaxLength());
	parser.setConformance(config.conformance());
	switch (config.quoting()) {
		case DOUBLE_QUOTE:
			parser.switchTo("DQID");
			break;
		case BACK_TICK:
			parser.switchTo("BTID");
			break;
		case BRACKET:
			parser.switchTo("DEFAULT");
			break;
	}

	return parser;
}
 
Example 2
Source Project: flink   Source File: CalciteParser.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Equivalent to {@link SqlParser#create(Reader, SqlParser.Config)}. The only
 * difference is we do not wrap the {@link FlinkSqlParserImpl} with {@link SqlParser}.
 *
 * <p>It is so that we can access specific parsing methods not accessible through the {@code SqlParser}.
 */
private SqlAbstractParserImpl createFlinkParser(String expr) {
	SourceStringReader reader = new SourceStringReader(expr);
	SqlAbstractParserImpl parser = config.parserFactory().getParser(reader);
	parser.setTabSize(1);
	parser.setQuotedCasing(config.quotedCasing());
	parser.setUnquotedCasing(config.unquotedCasing());
	parser.setIdentifierMaxLength(config.identifierMaxLength());
	parser.setConformance(config.conformance());
	switch (config.quoting()) {
		case DOUBLE_QUOTE:
			parser.switchTo("DQID");
			break;
		case BACK_TICK:
			parser.switchTo("BTID");
			break;
		case BRACKET:
			parser.switchTo("DEFAULT");
			break;
	}

	return parser;
}
 
Example 3
Source Project: flink   Source File: TableApiIdentifierParsingTest.java    License: Apache License 2.0 5 votes vote down vote up
private FlinkSqlParserImpl createFlinkParser(String expr) {
	SourceStringReader reader = new SourceStringReader(expr);
	FlinkSqlParserImpl parser = (FlinkSqlParserImpl) FlinkSqlParserImpl.FACTORY.getParser(reader);
	parser.setTabSize(1);
	parser.setUnquotedCasing(Lex.JAVA.unquotedCasing);
	parser.setQuotedCasing(Lex.JAVA.quotedCasing);
	parser.setIdentifierMaxLength(256);
	parser.setConformance(FlinkSqlConformance.DEFAULT);
	parser.switchTo("BTID");

	return parser;
}
 
Example 4
Source Project: flink   Source File: FlinkDDLDataTypeTest.java    License: Apache License 2.0 4 votes vote down vote up
public SqlParser createParser(String sql) {
	return SqlParser.create(new SourceStringReader(sql), parserConfig);
}
 
Example 5
Source Project: calcite   Source File: SqlTestFactory.java    License: Apache License 2.0 4 votes vote down vote up
public SqlParser createParser(String sql) {
  return SqlParser.create(new SourceStringReader(sql), parserConfig.get());
}
 
Example 6
Source Project: Bats   Source File: SqlParser.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Creates a <code>SqlParser</code> to parse the given string using the
 * parser implementation created from given {@link SqlParserImplFactory}
 * with given quoting syntax and casing policies for identifiers.
 *
 * @param sql A SQL statement or expression to parse
 * @param config The parser configuration (identifier max length, etc.)
 * @return A parser
 */
public static SqlParser create(String sql, Config config) {
  return create(new SourceStringReader(sql), config);
}
 
Example 7
Source Project: calcite   Source File: SqlParser.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Creates a <code>SqlParser</code> to parse the given string using the
 * parser implementation created from given {@link SqlParserImplFactory}
 * with given quoting syntax and casing policies for identifiers.
 *
 * @param sql A SQL statement or expression to parse
 * @param config The parser configuration (identifier max length, etc.)
 * @return A parser
 */
public static SqlParser create(String sql, Config config) {
  return create(new SourceStringReader(sql), config);
}
 
Example 8
Source Project: calcite   Source File: Planner.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Parses and validates a SQL statement.
 *
 * @param sql The SQL statement to parse.
 * @return The root node of the SQL parse tree.
 * @throws org.apache.calcite.sql.parser.SqlParseException on parse error
 */
default SqlNode parse(String sql) throws SqlParseException {
  return parse(new SourceStringReader(sql));
}