Search in sources :

Example 1 with OptionValue

use of org.apache.drill.exec.server.options.OptionValue in project drill by apache.

the class TestConvertFunctions method testBigIntVarCharReturnTripConvertLogical_ScalarReplaceON.

// TODO(DRILL-2326) temporary until we fix the scalar replacement bug for this case
@Test
// Because this test sometimes fails, sometimes succeeds
@Ignore
public void testBigIntVarCharReturnTripConvertLogical_ScalarReplaceON() throws Exception {
    final OptionValue srOption = QueryTestUtil.setupScalarReplacementOption(bits[0], ScalarReplacementOption.ON);
    boolean caughtException = false;
    try {
        // this used to fail (with a JUnit assertion) until we fix the SR bug
        // Something in DRILL-5116 seemed to fix this problem, so the test now
        // succeeds - sometimes.
        testBigIntVarCharReturnTripConvertLogical();
    } catch (RpcException e) {
        caughtException = true;
    } finally {
        QueryTestUtil.restoreScalarReplacementOption(bits[0], srOption);
    }
    // Yes: sometimes this works, sometimes it does not...
    assertTrue(!caughtException || caughtException);
}
Also used : RpcException(org.apache.drill.exec.rpc.RpcException) OptionValue(org.apache.drill.exec.server.options.OptionValue) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with OptionValue

use of org.apache.drill.exec.server.options.OptionValue in project drill by apache.

the class UserSession method setSessionOption.

/**
   * Set the option of a session level.
   * Note: Option's kind is automatically detected if such option exists.
   *
   * @param name option name
   * @param value option value
   */
public void setSessionOption(String name, String value) {
    OptionValue.Kind optionKind = SystemOptionManager.getValidator(name).getKind();
    OptionValue optionValue = OptionValue.createOption(optionKind, OptionValue.OptionType.SESSION, name, value);
    sessionOptions.setOption(optionValue);
}
Also used : OptionValue(org.apache.drill.exec.server.options.OptionValue)

Example 3 with OptionValue

use of org.apache.drill.exec.server.options.OptionValue in project drill by apache.

the class SetOptionHandler method getPlan.

@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, ForemanSetupException {
    final SqlSetOption option = unwrap(sqlNode, SqlSetOption.class);
    final SqlNode value = option.getValue();
    if (value != null && !(value instanceof SqlLiteral)) {
        throw UserException.validationError().message("Drill does not support assigning non-literal values in SET statements.").build(logger);
    }
    final String scope = option.getScope();
    final OptionValue.OptionType type;
    if (scope == null) {
        // No scope mentioned assumed SESSION
        type = OptionType.SESSION;
    } else {
        switch(scope.toLowerCase()) {
            case "session":
                type = OptionType.SESSION;
                break;
            case "system":
                type = OptionType.SYSTEM;
                break;
            default:
                throw UserException.validationError().message("Invalid OPTION scope %s. Scope must be SESSION or SYSTEM.", scope).build(logger);
        }
    }
    final OptionManager options = context.getOptions();
    if (type == OptionType.SYSTEM) {
        // administrative privileges.
        if (context.isUserAuthenticationEnabled() && !ImpersonationUtil.hasAdminPrivileges(context.getQueryUserName(), options.getOption(ExecConstants.ADMIN_USERS_VALIDATOR), options.getOption(ExecConstants.ADMIN_USER_GROUPS_VALIDATOR))) {
            throw UserException.permissionError().message("Not authorized to change SYSTEM options.").build(logger);
        }
    }
    // Currently, we convert multi-part identifier to a string.
    final String name = option.getName().toString();
    if (value != null) {
        // SET option
        final OptionValue optionValue = createOptionValue(name, type, (SqlLiteral) value);
        options.setOption(optionValue);
    } else {
        // RESET option
        if ("ALL".equalsIgnoreCase(name)) {
            options.deleteAllOptions(type);
        } else {
            options.deleteOption(name, type);
        }
    }
    return DirectPlan.createDirectPlan(context, true, String.format("%s updated.", name));
}
Also used : OptionValue(org.apache.drill.exec.server.options.OptionValue) SqlSetOption(org.apache.calcite.sql.SqlSetOption) NlsString(org.apache.calcite.util.NlsString) SqlLiteral(org.apache.calcite.sql.SqlLiteral) OptionType(org.apache.drill.exec.server.options.OptionValue.OptionType) OptionManager(org.apache.drill.exec.server.options.OptionManager) SqlNode(org.apache.calcite.sql.SqlNode)

Example 4 with OptionValue

use of org.apache.drill.exec.server.options.OptionValue in project drill by apache.

the class OptionIterator method next.

@Override
public OptionValueWrapper next() {
    final OptionValue value = mergedOptions.next();
    final Status status;
    if (value.type == OptionType.BOOT) {
        status = Status.BOOT;
    } else {
        final OptionValue def = SystemOptionManager.getValidator(value.name).getDefault();
        if (value.equalsIgnoreType(def)) {
            status = Status.DEFAULT;
        } else {
            status = Status.CHANGED;
        }
    }
    return new OptionValueWrapper(value.name, value.kind, value.type, value.num_val, value.string_val, value.bool_val, value.float_val, status);
}
Also used : OptionValue(org.apache.drill.exec.server.options.OptionValue)

Example 5 with OptionValue

use of org.apache.drill.exec.server.options.OptionValue in project drill by apache.

the class ControlsInjectionUtil method setControls.

public static void setControls(final UserSession session, final String controls) {
    validateControlsString(controls);
    final OptionValue opValue = OptionValue.createString(OptionValue.OptionType.SESSION, DRILLBIT_CONTROL_INJECTIONS, controls);
    final OptionManager options = session.getOptions();
    try {
        DRILLBIT_CONTROLS_VALIDATOR.validate(opValue, null);
        options.setOption(opValue);
    } catch (final Exception e) {
        fail("Could not set controls options: " + e.getMessage());
    }
    // to simulate that a query completed
    incrementer.increment(session);
}
Also used : OptionValue(org.apache.drill.exec.server.options.OptionValue) OptionManager(org.apache.drill.exec.server.options.OptionManager) RpcException(org.apache.drill.exec.rpc.RpcException)

Aggregations

OptionValue (org.apache.drill.exec.server.options.OptionValue)8 OptionManager (org.apache.drill.exec.server.options.OptionManager)4 RpcException (org.apache.drill.exec.rpc.RpcException)2 Test (org.junit.Test)2 SqlLiteral (org.apache.calcite.sql.SqlLiteral)1 SqlNode (org.apache.calcite.sql.SqlNode)1 SqlSetOption (org.apache.calcite.sql.SqlSetOption)1 NlsString (org.apache.calcite.util.NlsString)1 DrillbitContext (org.apache.drill.exec.server.DrillbitContext)1 OptionType (org.apache.drill.exec.server.options.OptionValue.OptionType)1 Ignore (org.junit.Ignore)1