Search in sources :

Example 1 with Determinism

use of com.facebook.presto.sql.tree.RoutineCharacteristics.Determinism in project presto by prestodb.

the class AstBuilder method getRoutineCharacteristics.

private RoutineCharacteristics getRoutineCharacteristics(SqlBaseParser.RoutineCharacteristicsContext context) {
    Language language = null;
    Determinism determinism = null;
    NullCallClause nullCallClause = null;
    for (SqlBaseParser.RoutineCharacteristicContext characteristic : context.routineCharacteristic()) {
        if (characteristic.language() != null) {
            if (language != null) {
                throw new ParsingException(format("Duplicate language clause: %s", characteristic.language().getText()), getLocation(characteristic.language()));
            }
            if (characteristic.language().SQL() != null) {
                language = Language.SQL;
            } else {
                language = new Language(((Identifier) visit(characteristic.language().identifier())).getValue());
            }
        } else if (characteristic.determinism() != null) {
            if (determinism != null) {
                throw new ParsingException(format("Duplicate determinism characteristics: %s", characteristic.determinism().getText()), getLocation(characteristic.determinism()));
            }
            determinism = characteristic.determinism().NOT() == null ? DETERMINISTIC : NOT_DETERMINISTIC;
        } else if (characteristic.nullCallClause() != null) {
            if (nullCallClause != null) {
                throw new ParsingException(format("Duplicate null-call clause: %s", characteristic.nullCallClause().getText()), getLocation(characteristic.nullCallClause()));
            }
            nullCallClause = characteristic.nullCallClause().CALLED() != null ? CALLED_ON_NULL_INPUT : RETURNS_NULL_ON_NULL_INPUT;
        } else {
            throw new IllegalArgumentException(format("Unsupported RoutineCharacteristic: %s", characteristic.getText()));
        }
    }
    return new RoutineCharacteristics(Optional.ofNullable(language), Optional.ofNullable(determinism), Optional.ofNullable(nullCallClause));
}
Also used : Determinism(com.facebook.presto.sql.tree.RoutineCharacteristics.Determinism) Identifier(com.facebook.presto.sql.tree.Identifier) Language(com.facebook.presto.sql.tree.RoutineCharacteristics.Language) RoutineCharacteristics(com.facebook.presto.sql.tree.RoutineCharacteristics) AlterRoutineCharacteristics(com.facebook.presto.sql.tree.AlterRoutineCharacteristics) NullCallClause(com.facebook.presto.sql.tree.RoutineCharacteristics.NullCallClause)

Aggregations

AlterRoutineCharacteristics (com.facebook.presto.sql.tree.AlterRoutineCharacteristics)1 Identifier (com.facebook.presto.sql.tree.Identifier)1 RoutineCharacteristics (com.facebook.presto.sql.tree.RoutineCharacteristics)1 Determinism (com.facebook.presto.sql.tree.RoutineCharacteristics.Determinism)1 Language (com.facebook.presto.sql.tree.RoutineCharacteristics.Language)1 NullCallClause (com.facebook.presto.sql.tree.RoutineCharacteristics.NullCallClause)1