Here are the examples of the java api com.dremio.options.OptionValue taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
60 Examples
19
Source : TestOptionManagerWrapper.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Test
public void testGetDefaultOptions() throws Exception {
OptionManager optionManager = OptionManagerWrapper.Builder.newBuilder().withOptionValidatorProvider(optionValidatorListing).withOptionManager(defaultOptionManager).withOptionManager(systemOptionManager).withOptionManager(sessionOptionManager).withOptionManager(queryOptionManager).build();
OptionList defaultOptions = optionManager.getDefaultOptions();
// Check only default options are returned
replacedertEquals(defaultOptionManager.getDefaultOptions().size(), defaultOptions.size());
for (OptionValue defaultOption : defaultOptions) {
replacedertEquals(defaultOption, optionValidatorListing.getValidator(defaultOption.getName()).getDefault());
}
}
19
Source : OptionValueStore.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
private byte[] serialize(OptionValue instance) {
try {
return serializer.serialize(instance);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
18
Source : TestSystemOptionManager.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
private OptionValue registerTestOption(OptionValue.Kind kind, String name, String defaultValue) {
OptionValue defaultOptionValue = OptionValue.createOption(kind, OptionValue.OptionType.SYSTEM, name, defaultValue);
OptionValidator optionValidator = mock(OptionValidator.clreplaced);
when(optionValidator.getDefault()).thenReturn(defaultOptionValue);
doReturn(optionValidator).when(optionValidatorListing).getValidator(name);
doReturn(true).when(optionValidatorListing).isValid(name);
return defaultOptionValue;
}
18
Source : OptionValueStore.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
public void put(String key, OptionValue value) {
store.put(key, serialize(value));
}
18
Source : FragmentOptionManager.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Override
public boolean setOption(OptionValue value) {
throw new UnsupportedOperationException("FragmentOptionManager does not support options mutation.");
}
18
Source : EagerCachingOptionManager.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Override
public boolean setOption(OptionValue value) {
return super.setOption(value) && delegate.setOption(value);
}
18
Source : DefaultOptionManager.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Override
public boolean setOption(OptionValue value) {
throw new UnsupportedOperationException("Cannot set option in DefaultOptionManager");
}
18
Source : CachingOptionManager.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Override
public boolean setOption(OptionValue value) {
throw new UnsupportedOperationException("NYI");
}
18
Source : SettingsResource.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@DELETE
@Path("{id}")
public Response resetSetting(@PathParam("id") String id) {
if (!projectOptionManager.isValid(id)) {
return Response.status(Status.NOT_FOUND).build();
}
// Client tool options should not be removable.
if (CLIENT_TOOL_OPTIONS.contains(id)) {
return Response.status(Status.BAD_REQUEST).build();
}
OptionValue option = projectOptionManager.getOption(id);
projectOptionManager.deleteOption(id, option.getType());
return Response.ok().build();
}
18
Source : SettingsResource.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@POST
public SettingsWrapperObject list(/* Body */
SettingsRequest request) {
Preconditions.checkNotNull(request, "request could not be null");
Set<String> requiredSettings = request.getRequiredSettings();
if (requiredSettings == null) {
requiredSettings = Collections.emptySet();
}
List<Setting> settings = new ArrayList<>();
if (requiredSettings.size() != 0 || request.getIncludeSetSettings()) {
for (OptionValue optionValue : projectOptionManager) {
if (requiredSettings.contains(optionValue.getName()) || (request.getIncludeSetSettings() && projectOptionManager.isSet(optionValue.getName()))) {
settings.add(toSetting(optionValue));
}
}
}
return new SettingsWrapperObject(settings);
}
18
Source : ProjectOptionManagerWrapper.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Override
public boolean setOption(OptionValue value) {
if (!projectOptionManager.setOption(value)) {
throw new IllegalArgumentException("Could not set option");
}
return true;
}
17
Source : TestSystemOptionManager.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Test
public void testIsSet() {
registerTestOption(OptionValue.Kind.LONG, "set-option", "0");
registerTestOption(OptionValue.Kind.LONG, "not-set-option", "1");
OptionValue optionValue = OptionValue.createLong(OptionValue.OptionType.SYSTEM, "set-option", 123);
OptionValueProtoList optionList = OptionValueProtoList.newBuilder().addAllOptions(Collections.singletonList(OptionValueProtoUtils.toOptionValueProto(optionValue))).build();
when(kvStore.get(OPTIONS_KEY)).thenReturn(optionList);
replacedertTrue(som.isSet("set-option"));
replacedertFalse(som.isSet("not-set-option"));
}
17
Source : TestSystemOptionManager.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Test
public void testGet() {
registerTestOption(OptionValue.Kind.LONG, "test-option", "0");
OptionValue optionValue = OptionValue.createLong(OptionValue.OptionType.SYSTEM, "test-option", 123);
OptionValueProtoList optionList = OptionValueProtoList.newBuilder().addAllOptions(Collections.singletonList(OptionValueProtoUtils.toOptionValueProto(optionValue))).build();
when(kvStore.get(OPTIONS_KEY)).thenReturn(optionList);
replacedertEquals(optionValue, som.getOption(optionValue.getName()));
verify(kvStore, times(1)).get(eq(OPTIONS_KEY));
replacedertNull(som.getOption("not-a-real-option"));
}
17
Source : TestOptionValueProtoUtils.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Test
public void testStringOptionToProto() {
final OptionValue option = OptionValue.createString(OptionValue.OptionType.SYSTEM, "test.option", "test-option");
final OptionValueProto optionProto = OptionValueProtoUtils.toOptionValueProto(option);
replacedertTrue(verifyEquivalent(option, optionProto));
}
17
Source : TestOptionManagerWrapper.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Test
public void testGetFallback() throws Exception {
String testOptionName = SLICE_TARGET;
OptionManager optionManager = OptionManagerWrapper.Builder.newBuilder().withOptionValidatorProvider(optionValidatorListing).withOptionManager(defaultOptionManager).withOptionManager(systemOptionManager).withOptionManager(sessionOptionManager).withOptionManager(queryOptionManager).build();
// Set value directly to specific OM and check specific OM's for value
long newValue1 = 10;
OptionValue optionValue1 = OptionValue.createLong(OptionValue.OptionType.SYSTEM, testOptionName, newValue1);
systemOptionManager.setOption(optionValue1);
replacedertEquals(optionValue1, optionManager.getOption(testOptionName));
// Check other OM's and make sure option was not set
replacedertEquals(null, sessionOptionManager.getOption(testOptionName));
replacedertEquals(null, queryOptionManager.getOption(testOptionName));
// Set another option
long newValue2 = 20;
OptionValue optionValue2 = OptionValue.createLong(OptionValue.OptionType.SESSION, testOptionName, newValue2);
sessionOptionManager.setOption(optionValue2);
replacedertEquals(optionValue2, optionManager.getOption(testOptionName));
// Check previously set option is still present
replacedertEquals(optionValue1, systemOptionManager.getOption(testOptionName));
// Check other OM's and make sure option was not set
replacedertEquals(null, queryOptionManager.getOption(testOptionName));
}
17
Source : TestOptionManagerWrapper.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Test
public void testSetFallback() throws Exception {
String testOptionName = SLICE_TARGET;
OptionManager optionManager = OptionManagerWrapper.Builder.newBuilder().withOptionValidatorProvider(optionValidatorListing).withOptionManager(defaultOptionManager).withOptionManager(systemOptionManager).withOptionManager(sessionOptionManager).withOptionManager(queryOptionManager).build();
// Set value and check specific OM's for value
long newValue1 = 10;
OptionValue optionValue1 = OptionValue.createLong(OptionValue.OptionType.SESSION, testOptionName, newValue1);
optionManager.setOption(optionValue1);
replacedertEquals(sessionOptionManager.getOption(testOptionName), optionValue1);
// Check other OM's and make sure option was not set
replacedertEquals(null, systemOptionManager.getOption(testOptionName));
replacedertEquals(null, queryOptionManager.getOption(testOptionName));
// Set another option
long newValue2 = 20;
OptionValue optionValue2 = OptionValue.createLong(OptionValue.OptionType.SYSTEM, testOptionName, newValue2);
optionManager.setOption(optionValue2);
replacedertEquals(optionValue2, systemOptionManager.getOption(testOptionName));
// Check previously set option is still present
replacedertEquals(optionValue1, sessionOptionManager.getOption(testOptionName));
// Check other OM's and make sure option was not set
replacedertEquals(null, queryOptionManager.getOption(testOptionName));
}
17
Source : TestEagerCachingOptionManager.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
public clreplaced TestEagerCachingOptionManager {
private OptionManager optionManager;
private OptionList optionList;
private OptionValue optionValueA;
private OptionValue optionValueB;
private OptionValue optionValueC;
@Before
public void setup() {
optionManager = mock(OptionManager.clreplaced);
optionList = new OptionList();
optionValueA = OptionValue.createDouble(OptionValue.OptionType.SYSTEM, "testOptionA", 2);
optionValueB = OptionValue.createBoolean(OptionValue.OptionType.SYSTEM, "testOptionB", true);
optionValueC = OptionValue.createString(OptionValue.OptionType.SYSTEM, "testOptionC", "someValue");
optionList.add(optionValueA);
optionList.add(optionValueB);
optionList.add(optionValueC);
when(optionManager.getNonDefaultOptions()).thenReturn(optionList);
}
@Test
public void testInitialization() {
new EagerCachingOptionManager(optionManager);
verify(optionManager, times(1)).getNonDefaultOptions();
}
@Test
public void testGetOption() {
final OptionManager eagerCachingOptionManager = new EagerCachingOptionManager(optionManager);
replacedertEquals(optionValueA, eagerCachingOptionManager.getOption(optionValueA.getName()));
// getOption should not touch underlying option manager
verify(optionManager, times(0)).getOption(optionValueA.getName());
}
@Test
public void testSetOption() {
final OptionManager eagerCachingOptionManager = new EagerCachingOptionManager(optionManager);
final OptionValue newOption = OptionValue.createBoolean(OptionValue.OptionType.SYSTEM, "newOption", true);
eagerCachingOptionManager.setOption(newOption);
// setOption should write-through to underlying option manager
verify(optionManager, times(1)).setOption(newOption);
}
@Test
public void testDeleteOption() {
final OptionManager eagerCachingOptionManager = new EagerCachingOptionManager(optionManager);
eagerCachingOptionManager.deleteOption(optionValueC.getName(), OptionValue.OptionType.SYSTEM);
replacedertNull(eagerCachingOptionManager.getOption(optionValueC.getName()));
// deleteOption should write-through to underlying option manager
verify(optionManager, times(1)).deleteOption(optionValueC.getName(), OptionValue.OptionType.SYSTEM);
}
@Test
public void testDeleteAllOptions() {
final OptionManager eagerCachingOptionManager = new EagerCachingOptionManager(optionManager);
eagerCachingOptionManager.deleteAllOptions(OptionValue.OptionType.SYSTEM);
replacedertNull(eagerCachingOptionManager.getOption(optionValueA.getName()));
replacedertNull(eagerCachingOptionManager.getOption(optionValueB.getName()));
replacedertNull(eagerCachingOptionManager.getOption(optionValueC.getName()));
// deleteOption should write-through to underlying option manager
verify(optionManager, times(1)).deleteAllOptions(OptionValue.OptionType.SYSTEM);
}
}
17
Source : OptionManagerWrapper.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Override
public boolean setOption(OptionValue value) {
// ensure option exists
getValidator(value.getName());
return handleFallbackBoolean(optionManager -> optionManager.setOption(value));
}
17
Source : ClassCompilerSelector.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
public ClreplacedBytes[] getClreplacedByteCode(ClreplacedNames clreplacedName, String sourceCode) throws CompileException, ClreplacedNotFoundException, ClreplacedTransformationException, IOException {
OptionValue value = sessionOptions.getOption(JAVA_COMPILER_OPTION);
CompilerPolicy policy = (value != null) ? CompilerPolicy.valueOf(value.getStringVal().toUpperCase()) : defaultPolicy;
value = sessionOptions.getOption(JAVA_COMPILER_JANINO_MAXSIZE_OPTION);
long janinoThreshold = (value != null) ? value.getNumVal() : defaultJaninoThreshold;
value = sessionOptions.getOption(JAVA_COMPILER_DEBUG_OPTION);
boolean debug = (value != null) ? value.getBoolVal() : defaultDebug;
ClreplacedCompiler clreplacedCompiler;
if (jdkClreplacedCompiler != null && (policy == CompilerPolicy.JDK || (policy == CompilerPolicy.DEFAULT && sourceCode.length() > janinoThreshold))) {
clreplacedCompiler = jdkClreplacedCompiler;
} else {
clreplacedCompiler = janinoClreplacedCompiler;
}
ClreplacedBytes[] bc = clreplacedCompiler.getClreplacedByteCode(clreplacedName, sourceCode, debug);
/*
* final String baseDir = System.getProperty("java.io.tmpdir") + File.separator + clreplacedCompiler.getClreplaced().getSimpleName();
* File clreplacedFile = new File(baseDir + clreplacedName.clazz);
* clreplacedFile.getParentFile().mkdirs();
* BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(clreplacedFile));
* out.write(bc[0]);
* out.close();
*/
return bc;
}
17
Source : SettingsResource.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@SuppressWarnings("rawtypes")
private Setting toSetting(OptionValue option) {
switch(option.getKind()) {
case BOOLEAN:
return new Setting.BooleanSetting(option.getName(), option.getBoolVal());
case DOUBLE:
return new Setting.FloatSetting(option.getName(), option.getFloatVal());
case LONG:
return new Setting.IntegerSetting(option.getName(), option.getNumVal());
case STRING:
return new Setting.TextSetting(option.getName(), option.getStringVal());
default:
throw new IllegalStateException("Unable to handle kind " + option.getKind());
}
}
17
Source : ProjectOptionManagerWrapper.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Override
public OptionValue getOption(String name) {
OptionValue result = projectOptionManager.getOption(name);
if (result == null) {
return defaultOptionManager.getOption(name);
}
return result;
}
16
Source : TestSystemOptionManager.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Test
public void testGetNonDefaultOptions() {
registerTestOption(OptionValue.Kind.LONG, "test-option-0", "0");
registerTestOption(OptionValue.Kind.LONG, "test-option-1", "1");
OptionValue optionValue0 = OptionValue.createLong(OptionValue.OptionType.SYSTEM, "test-option-0", 100);
OptionValue optionValue1 = OptionValue.createLong(OptionValue.OptionType.SYSTEM, "test-option-1", 111);
OptionValueProtoList optionList = OptionValueProtoList.newBuilder().addAllOptions(Arrays.asList(OptionValueProtoUtils.toOptionValueProto(optionValue0), OptionValueProtoUtils.toOptionValueProto(optionValue1))).build();
when(kvStore.get(OPTIONS_KEY)).thenReturn(optionList);
replacedertThat(som.getNonDefaultOptions(), containsInAnyOrder(optionValue0, optionValue1));
}
16
Source : TestSystemOptionManager.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Test
public void testSet() {
registerTestOption(OptionValue.Kind.LONG, "already-added-option", "0");
OptionValue toAddOptionDefault = registerTestOption(OptionValue.Kind.STRING, "to-add-option", "default-value");
OptionValue alreadyAddedOption = OptionValue.createLong(OptionValue.OptionType.SYSTEM, "already-added-option", 123);
OptionValue toAddOption = OptionValue.createString(OptionValue.OptionType.SYSTEM, "to-add-option", "some-value");
OptionValueProtoList optionList = OptionValueProtoList.newBuilder().addAllOptions(Collections.singletonList(OptionValueProtoUtils.toOptionValueProto(alreadyAddedOption))).build();
when(kvStore.get(OPTIONS_KEY)).thenReturn(optionList);
// Re-adding same option should exit early
som.setOption(alreadyAddedOption);
verify(kvStore, times(0)).put(any(), any());
// Adding a option with default value should exit early
som.setOption(toAddOptionDefault);
verify(kvStore, times(0)).put(any(), any());
// regular add option
som.setOption(toAddOption);
ArgumentCaptor<OptionValueProtoList> argument = ArgumentCaptor.forClreplaced(OptionValueProtoList.clreplaced);
verify(kvStore, times(1)).put(eq(OPTIONS_KEY), argument.capture());
replacedertThat(argument.getValue().getOptionsList(), containsInAnyOrder(OptionValueProtoUtils.toOptionValueProto(toAddOption), OptionValueProtoUtils.toOptionValueProto(alreadyAddedOption)));
// Overriding an option
OptionValue overridingOption = OptionValue.createLong(OptionValue.OptionType.SYSTEM, "already-added-option", 999);
som.setOption(overridingOption);
verify(kvStore, times(1)).put(OPTIONS_KEY, OptionValueProtoList.newBuilder().addAllOptions(Collections.singletonList(OptionValueProtoUtils.toOptionValueProto(overridingOption))).build());
}
16
Source : TestSystemOptionManager.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Test
public void tesreplacederator() {
registerTestOption(OptionValue.Kind.LONG, "test-option-0", "0");
registerTestOption(OptionValue.Kind.LONG, "test-option-1", "1");
OptionValue optionValue0 = OptionValue.createLong(OptionValue.OptionType.SYSTEM, "test-option-0", 100);
OptionValue optionValue1 = OptionValue.createLong(OptionValue.OptionType.SYSTEM, "test-option-1", 111);
OptionValueProtoList optionList = OptionValueProtoList.newBuilder().addAllOptions(Arrays.asList(OptionValueProtoUtils.toOptionValueProto(optionValue0), OptionValueProtoUtils.toOptionValueProto(optionValue1))).build();
when(kvStore.get(OPTIONS_KEY)).thenReturn(optionList);
replacedertThat(Lists.from(som.iterator()), containsInAnyOrder(optionValue0, optionValue1));
}
16
Source : TestSystemOptionManager.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Test
public void testDelete() {
registerTestOption(OptionValue.Kind.LONG, "added-option-0", "0");
registerTestOption(OptionValue.Kind.LONG, "added-option-1", "1");
registerTestOption(OptionValue.Kind.STRING, "not-added-option", "default-value");
OptionValue optionValue0 = OptionValue.createLong(OptionValue.OptionType.SYSTEM, "added-option-0", 100);
OptionValue optionValue1 = OptionValue.createLong(OptionValue.OptionType.SYSTEM, "added-option-1", 111);
OptionValueProtoList optionList = OptionValueProtoList.newBuilder().addAllOptions(Arrays.asList(OptionValueProtoUtils.toOptionValueProto(optionValue0), OptionValueProtoUtils.toOptionValueProto(optionValue1))).build();
when(kvStore.get(OPTIONS_KEY)).thenReturn(optionList);
// Attempt to option that is not in som should exit early
som.deleteOption("not-added-option", OptionValue.OptionType.SYSTEM);
verify(kvStore, times(0)).put(any(), any());
// regular delete option
som.deleteOption("added-option-0", OptionValue.OptionType.SYSTEM);
verify(kvStore, times(1)).put(OPTIONS_KEY, OptionValueProtoList.newBuilder().addAllOptions(Collections.singletonList(OptionValueProtoUtils.toOptionValueProto(optionValue1))).build());
}
16
Source : TestOptionValueProtoUtils.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Test
public void testStringOptionFromProto() {
final OptionValueProto optionProto = OptionValueProto.newBuilder().setName("test.option").setStringVal("test-option").build();
final OptionValue option = OptionValueProtoUtils.toOptionValue(optionProto);
replacedertTrue(verifyEquivalent(option, optionProto));
}
16
Source : TestOptionValueProtoUtils.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
private void checkName(OptionValue optionValue, OptionValueProto optionValueProto) {
replacedertEquals(optionValue.getName(), optionValueProto.getName());
}
16
Source : TestOptionValueProtoUtils.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Test
public void testLongOptionFromProto() {
final OptionValueProto optionProto = OptionValueProto.newBuilder().setName("test.option").setNumVal(1234).build();
final OptionValue option = OptionValueProtoUtils.toOptionValue(optionProto);
replacedertTrue(verifyEquivalent(option, optionProto));
}
16
Source : TestOptionValueProtoUtils.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Test
public void testLongOptionToProto() {
final OptionValue option = OptionValue.createLong(OptionValue.OptionType.SYSTEM, "test.option", 1234);
final OptionValueProto optionProto = OptionValueProtoUtils.toOptionValueProto(option);
replacedertTrue(verifyEquivalent(option, optionProto));
}
16
Source : TestOptionValueProtoUtils.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Test
public void testBoolOptionFromProto() {
final OptionValueProto optionProto = OptionValueProto.newBuilder().setName("test.option").setBoolVal(true).build();
final OptionValue option = OptionValueProtoUtils.toOptionValue(optionProto);
replacedertTrue(verifyEquivalent(option, optionProto));
}
16
Source : TestOptionValueProtoUtils.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Test
public void testFloatOptionFromProto() {
final OptionValueProto optionProto = OptionValueProto.newBuilder().setName("test.option").setFloatVal(1234.1234).build();
final OptionValue option = OptionValueProtoUtils.toOptionValue(optionProto);
replacedertTrue(verifyEquivalent(option, optionProto));
}
16
Source : TestOptionValueProtoUtils.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Test
public void testBoolOptionToProto() {
final OptionValue option = OptionValue.createBoolean(OptionValue.OptionType.SYSTEM, "test.option", true);
final OptionValueProto optionProto = OptionValueProtoUtils.toOptionValueProto(option);
replacedertTrue(verifyEquivalent(option, optionProto));
}
16
Source : TestOptionValueProtoUtils.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Test
public void testDoubleOptionToProto() {
final OptionValue option = OptionValue.createDouble(OptionValue.OptionType.SYSTEM, "test.option", 1234.1234);
final OptionValueProto optionProto = OptionValueProtoUtils.toOptionValueProto(option);
replacedertTrue(verifyEquivalent(option, optionProto));
}
16
Source : TestOptionManagerWrapper.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Test
public void testGetAndSetOption() throws Exception {
String testOptionName = SLICE_TARGET;
OptionManager optionManager = OptionManagerWrapper.Builder.newBuilder().withOptionValidatorProvider(optionValidatorListing).withOptionManager(defaultOptionManager).withOptionManager(systemOptionManager).build();
OptionValue optionValue = optionManager.getOption(testOptionName);
// Sanity check default value
replacedertEquals(optionValidatorListing.getValidator(testOptionName).getDefault().getNumVal(), optionValue.getNumVal());
long newValue = 10;
optionManager.setOption(OptionValue.createLong(OptionValue.OptionType.SYSTEM, testOptionName, newValue));
optionValue = optionManager.getOption(testOptionName);
replacedertEquals((Long) newValue, optionValue.getNumVal());
}
16
Source : SettingsResource.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@PUT
@Path("{id}")
public Response setSetting(Setting updatedSetting, @PathParam("id") String id) {
if (!projectOptionManager.isValid(id)) {
return Response.status(Status.NOT_FOUND).build();
}
OptionValue optionValue = toOptionValue(updatedSetting);
projectOptionManager.setOption(optionValue);
return Response.ok(toSetting(projectOptionManager.getOption(id))).build();
}
15
Source : TestSystemOptionManagerMigration.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Test
public void testMigrationFromJson() throws Exception {
// Legacy Store to directly add legacy options
final OptionValueStore legacyStore = new OptionValueStore(() -> kvStoreProvider, SystemOptionManager.LegacyJacksonOptionStoreCreator.clreplaced, new JacksonSerializer<>(lpp.getMapper(), OptionValue.clreplaced));
legacyStore.start();
// put some options with old jackson serialized format
final OptionValue option1 = OptionValue.createBoolean(OptionValue.OptionType.SYSTEM, "planner.disable_exchanges", true);
// check legacy capitalization doesn't break
legacyStore.put("Planner.Disable_Exchanges", option1);
final OptionValue option2 = OptionValue.createLong(OptionValue.OptionType.SYSTEM, "planner.parreplacedioner_sender_threads_factor", 4);
legacyStore.put("planner.parreplacedioner_sender_threads_factor", option2);
// migrate
som.start();
// check options are deleted from legacy store
// old store should have no options
replacedertEquals(0, getNumOptions(legacyStore));
replacedertNull(legacyStore.get(option1.getName()));
replacedertNull(legacyStore.get(option2.getName()));
// check options match
replacedertEquals(som.getOption(option1.getName()), option1);
replacedertEquals(som.getOption(option2.getName()), option2);
}
15
Source : TestSystemOptionManager.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Test
public void testDeleteAll() {
registerTestOption(OptionValue.Kind.LONG, "test-option-0", "0");
registerTestOption(OptionValue.Kind.LONG, "test-option-1", "1");
OptionValue optionValue0 = OptionValue.createLong(OptionValue.OptionType.SYSTEM, "test-option-0", 100);
OptionValue optionValue1 = OptionValue.createLong(OptionValue.OptionType.SYSTEM, "test-option-1", 111);
OptionValueProtoList optionList = OptionValueProtoList.newBuilder().addAllOptions(Arrays.asList(OptionValueProtoUtils.toOptionValueProto(optionValue0), OptionValueProtoUtils.toOptionValueProto(optionValue1))).build();
when(kvStore.get(OPTIONS_KEY)).thenReturn(optionList);
som.deleteAllOptions(OptionValue.OptionType.SYSTEM);
verify(kvStore, times(1)).put(OPTIONS_KEY, OptionValueProtoList.newBuilder().addAllOptions(Collections.emptyList()).build());
}
15
Source : TestOptionManagerWrapper.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Test
public void testGetNonDefaultOptions() throws Exception {
OptionManager optionManager = OptionManagerWrapper.Builder.newBuilder().withOptionValidatorProvider(optionValidatorListing).withOptionManager(defaultOptionManager).withOptionManager(systemOptionManager).withOptionManager(sessionOptionManager).withOptionManager(queryOptionManager).build();
int initialOptionsCount = defaultOptionManager.getNonDefaultOptions().size() + systemOptionManager.getNonDefaultOptions().size() + sessionOptionManager.getNonDefaultOptions().size() + queryOptionManager.getNonDefaultOptions().size();
List<OptionValue> optionValues = Arrays.asList(OptionValue.createLong(OptionValue.OptionType.SYSTEM, SLICE_TARGET, 10), OptionValue.createLong(OptionValue.OptionType.SESSION, SLICE_TARGET, 15), OptionValue.createLong(OptionValue.OptionType.QUERY, SLICE_TARGET, 20), OptionValue.createBoolean(OptionValue.OptionType.SESSION, ENABLE_VERBOSE_ERRORS_KEY, true), OptionValue.createBoolean(OptionValue.OptionType.QUERY, ENABLE_VERBOSE_ERRORS_KEY, true));
optionValues.forEach(optionManager::setOption);
OptionList nonDefaultOptions = optionManager.getNonDefaultOptions();
// Check all set optionValues are returned
replacedertEquals(initialOptionsCount + optionValues.size(), nonDefaultOptions.size());
for (OptionValue optionValue : optionValues) {
replacedertTrue(nonDefaultOptions.contains(optionValue));
}
// Check no default options are returned
for (OptionValue nonDefaultOption : nonDefaultOptions) {
replacedertNotEquals(nonDefaultOption, defaultOptionManager.getOption(nonDefaultOption.getName()));
}
}
15
Source : TestOptionManagerWrapper.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Test
public void testFlippedOrdering() {
String testOptionName = SLICE_TARGET;
OptionValue testOptionDefault = optionValidatorListing.getValidator(testOptionName).getDefault();
// "Flipped" ordering
// DefaultOM will take priority
OptionManager optionManager2 = OptionManagerWrapper.Builder.newBuilder().withOptionValidatorProvider(optionValidatorListing).withOptionManager(systemOptionManager).withOptionManager(defaultOptionManager).build();
long newValue2 = 20;
OptionValue optionValue2 = OptionValue.createLong(OptionValue.OptionType.SYSTEM, testOptionName, newValue2);
try {
optionManager2.setOption(optionValue2);
replacedert.fail();
} catch (UnsupportedOperationException ignored) {
// Expect to hit default option manager, which should fail since set is not supported
}
// Sanity check default value is returned
replacedertEquals(testOptionDefault, optionManager2.getOption(testOptionName));
// Sanity check iterator
OptionList iteratorResult2 = new OptionList();
optionManager2.iterator().forEachRemaining(iteratorResult2::add);
replacedertTrue(iteratorResult2.contains(testOptionDefault));
}
15
Source : TestOptionManagerWrapper.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Test
public void testNormalOrdering() {
String testOptionName = SLICE_TARGET;
// "Normal" ordering
// SystemOM will take priority
OptionManager optionManager1 = OptionManagerWrapper.Builder.newBuilder().withOptionValidatorProvider(optionValidatorListing).withOptionManager(defaultOptionManager).withOptionManager(systemOptionManager).build();
long newValue1 = 10;
OptionValue optionValue1 = OptionValue.createLong(OptionValue.OptionType.SYSTEM, testOptionName, newValue1);
optionManager1.setOption(optionValue1);
replacedertEquals(optionValue1, optionManager1.getOption(testOptionName));
OptionList iteratorResult1 = new OptionList();
optionManager1.iterator().forEachRemaining(iteratorResult1::add);
replacedertTrue(iteratorResult1.contains(optionValue1));
}
15
Source : TestEagerCachingOptionManager.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Test
public void testSetOption() {
final OptionManager eagerCachingOptionManager = new EagerCachingOptionManager(optionManager);
final OptionValue newOption = OptionValue.createBoolean(OptionValue.OptionType.SYSTEM, "newOption", true);
eagerCachingOptionManager.setOption(newOption);
// setOption should write-through to underlying option manager
verify(optionManager, times(1)).setOption(newOption);
}
15
Source : TestSimpleLimitExchangeRemover.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Test
public void simpleSelectWithLimitWithSoftScanWithLeafLimitsEnabled() {
OptionValue optionEnabled = OptionValue.createBoolean(OptionValue.OptionType.QUERY, PlannerSettings.ENABLE_LEAF_LIMITS.getOptionName(), true);
when(optionManager.getOption(PlannerSettings.ENABLE_LEAF_LIMITS.getOptionName())).thenReturn(optionEnabled);
optionList.remove(PlannerSettings.ENABLE_LEAF_LIMITS.getDefault());
optionList.add(optionEnabled);
Prel input = newScreen(newLimit(0, 10, newProject(exprs(), rowType(), newUnionExchange(newLimit(0, 10, newProject(exprs(), rowType(), newSoftScan(rowType())))))));
Prel output = SimpleLimitExchangeRemover.apply(plannerSettings, input);
verifyOutput(output, "Screen", "Limit", "Project", "UnionExchange", "Limit", "Project", "SystemScan");
}
15
Source : SessionOptionManagerImpl.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Override
public boolean setOption(final OptionValue value) {
optionValidatorListing.getValidator(value.getName()).validate(value);
if (!super.setOption(value)) {
return false;
}
final String name = value.getName();
final OptionValidator validator = optionValidatorListing.getValidator(name);
final boolean shortLived = validator.isShortLived();
if (shortLived) {
// start from the next query
final int start = queryCount.get() + 1;
final int ttl = validator.getTtl();
final int end = start + ttl;
shortLivedOptions.put(name, new ImmutablePair<>(start, end));
}
return true;
}
15
Source : SessionOptionManagerImpl.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Override
public OptionValue getOption(final String name) {
final OptionValue value = super.getOption(name);
if (shortLivedOptions.containsKey(name)) {
if (withinRange(name)) {
return value;
}
final int queryNumber = queryCount.get();
final int start = shortLivedOptions.get(name).getLeft();
// option is not in effect if queryNumber < start
if (queryNumber < start) {
return optionValidatorListing.getValidator(name).getDefault();
// reset if queryNumber <= end
} else {
options.remove(name);
shortLivedOptions.remove(name);
// fallback takes effect
return null;
}
}
return value;
}
15
Source : InMemoryOptionManager.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Override
public boolean setOption(OptionValue value) {
if (supportsOptionType(value.getType())) {
options.put(value.getName(), value);
return true;
} else {
return false;
}
}
14
Source : TestSystemOptionManagerMigration.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Test
public void testIgnoreInvalidOption() throws Exception {
final LegacyKVStore<String, OptionValueProto> legacyStore = kvStoreProvider.getStore(SystemOptionManager.LegacyProtoOptionStoreCreator.clreplaced);
final OptionValue option1 = OptionValue.createBoolean(OptionValue.OptionType.SYSTEM, "invalid", true);
legacyStore.put("invalid", OptionValueProtoUtils.toOptionValueProto(option1));
// migrate
som.start();
replacedertNull(som.getOption("invalid"));
replacedertThat(som.getNonDefaultOptions(), not(hasItem(option1)));
}
14
Source : OptionIterator.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Override
public OptionValueWrapper next() {
final OptionValue value = mergedOptions.next();
final Status status;
if (value.getType() == OptionType.BOOT) {
status = Status.BOOT;
} else {
final OptionValue def = fragmentOptions.getOptionValidatorListing().getValidator(value.getName()).getDefault();
if (value.equalsIgnoreType(def)) {
status = Status.DEFAULT;
} else {
status = Status.CHANGED;
}
}
return new OptionValueWrapper(value.getName(), value.getKind(), value.getType(), value.getNumVal(), value.getStringVal(), value.getBoolVal(), value.getFloatVal(), status);
}
14
Source : SystemOptionManager.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Override
public boolean setOption(final OptionValue value) {
checkArgument(value.getType() == OptionType.SYSTEM, "OptionType must be SYSTEM.");
final String name = value.getName().toLowerCase(Locale.ROOT);
final OptionValidator validator = optionValidatorListing.getValidator(name);
// validate the option
validator.validate(value);
// temp map for convenient lookups
final Map<String, OptionValueProto> optionMap = new HashMap<>();
getOptionProtoList().forEach(optionProto -> optionMap.put(optionProto.getName(), optionProto));
// no need to set option if value is the same
if (optionMap.containsKey(name) && optionMap.get(name).equals(OptionValueProtoUtils.toOptionValueProto(value))) {
return true;
}
// Handle setting option to the default value
if (value.equals(validator.getDefault())) {
if (optionMap.containsKey(value.getName())) {
// If option was previously set, remove it
optionMap.remove(value.getName());
} else {
// If option was not set, skip the set completely
return true;
}
}
optionMap.put(name, OptionValueProtoUtils.toOptionValueProto(value));
options.put(OPTIONS_KEY, OptionValueProtoUtils.toOptionValueProtoList(optionMap.values()));
refreshAndNotifySiblings();
notifyListeners();
return true;
}
14
Source : SetOptionHandler.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
@Override
public List<SimpleCommandResult> toResult(String sql, SqlNode sqlNode) throws ValidationException, RelConversionException, IOException, ForemanSetupException {
final OptionManager options = context.getOptions();
final SqlSetOption option = SqlNodeUtil.unwrap(sqlNode, SqlSetOption.clreplaced);
final String name = option.getName().toString();
final SqlNode value = option.getValue();
if (value != null && !(value instanceof SqlLiteral)) {
throw UserException.validationError().message("Dremio does not support replacedigning non-literal values in SET statements.").build(logger);
}
final String scope = option.getScope();
final OptionValue.OptionType type;
if (scope == null) {
// No scope mentioned replacedumed 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);
}
}
// Currently, we convert multi-part identifier to a string.
if (value != null) {
// SET option
final OptionValue optionValue = createOptionValue(name, type, (SqlLiteral) value);
options.setOption(optionValue);
} else {
// RESET option
if ("ALL".equalsIgnoreCase(name)) {
session.setDefaultSchemaPath(null);
options.deleteAllOptions(type);
} else {
options.deleteOption(name, type);
}
}
return Collections.singletonList(SimpleCommandResult.successful("%s updated.", name));
}
14
Source : PlannerSettings.java
with Apache License 2.0
from dremio
with Apache License 2.0
from dremio
public double getMinimumCostPerSplit(SourceType sourceType) {
if (SOURCES_WITH_MIN_COST.contains(sourceType.value().toLowerCase())) {
if (logger.isDebugEnabled()) {
logger.debug("planner.cost.minimum.enable is enabled and SourceType {} supports minimum cost per split", sourceType.label());
}
OptionValue value = options.getOption(String.format("planner.%s.min_cost_per_split", sourceType.value().toLowerCase()));
if (value != null) {
return value.getFloatVal();
}
}
return options.getOption(DEFAULT_SCAN_MIN_COST);
}
See More Examples