use of org.apache.calcite.sql.fun.SqlLibrary in project calcite by apache.
the class StandardConvertletTable method convertSubstring.
/**
* Converts a SUBSTRING expression.
*
* <p>Called automatically via reflection.
*/
public RexNode convertSubstring(SqlRexContext cx, SqlSubstringFunction op, SqlCall call) {
final SqlLibrary library = cx.getValidator().config().conformance().semantics();
final SqlBasicCall basicCall = (SqlBasicCall) call;
switch(library) {
case BIG_QUERY:
return toRex(cx, basicCall, SqlLibraryOperators.SUBSTR_BIG_QUERY);
case MYSQL:
return toRex(cx, basicCall, SqlLibraryOperators.SUBSTR_MYSQL);
case ORACLE:
return toRex(cx, basicCall, SqlLibraryOperators.SUBSTR_ORACLE);
case POSTGRESQL:
default:
return convertFunction(cx, op, call);
}
}
use of org.apache.calcite.sql.fun.SqlLibrary in project calcite by apache.
the class DocumentationTest method testAllFunctionsAreDocumented.
/**
* Tests that every function in {@link SqlStdOperatorTable} is documented in
* reference.md.
*/
@Test
void testAllFunctionsAreDocumented() throws IOException {
final FileFixture f = new FileFixture();
final Map<String, PatternOp> map = new TreeMap<>();
addOperators(map, "", SqlStdOperatorTable.instance().getOperatorList());
for (SqlLibrary library : SqlLibrary.values()) {
switch(library) {
case STANDARD:
case SPATIAL:
continue;
}
addOperators(map, "\\| [^|]*" + library.abbrev + "[^|]* ", SqlLibraryOperatorTableFactory.INSTANCE.getOperatorTable(EnumSet.of(library)).getOperatorList());
}
final Set<String> regexSeen = new HashSet<>();
try (LineNumberReader r = new LineNumberReader(Util.reader(f.inFile))) {
for (; ; ) {
final String line = r.readLine();
if (line == null) {
break;
}
for (Map.Entry<String, PatternOp> entry : map.entrySet()) {
if (entry.getValue().pattern.matcher(line).matches()) {
// function is documented
regexSeen.add(entry.getKey());
}
}
}
}
final Set<String> regexNotSeen = new TreeSet<>(map.keySet());
regexNotSeen.removeAll(regexSeen);
assertThat("some functions are not documented: " + map.entrySet().stream().filter(e -> regexNotSeen.contains(e.getKey())).map(e -> e.getValue().opName + "(" + e.getKey() + ")").collect(Collectors.joining(", ")), regexNotSeen.isEmpty(), is(true));
}
use of org.apache.calcite.sql.fun.SqlLibrary in project calcite by apache.
the class CalciteConnectionConfigImpl method fun.
@Override
@PolyNull
public <T> T fun(Class<T> operatorTableClass, @PolyNull T defaultOperatorTable) {
final String fun = CalciteConnectionProperty.FUN.wrap(properties).getString();
if (fun == null || fun.equals("") || fun.equals("standard")) {
return defaultOperatorTable;
}
final List<SqlLibrary> libraryList = SqlLibrary.parse(fun);
final SqlOperatorTable operatorTable = SqlLibraryOperatorTableFactory.INSTANCE.getOperatorTable(ConsList.of(SqlLibrary.STANDARD, libraryList));
return operatorTableClass.cast(operatorTable);
}
Aggregations