@Test public void testSubstringNegative( @Injectable final DrillbitContext bitContext, @Injectable UserServer.UserClientConnection connection) throws Throwable { new NonStrictExpectations() { { bitContext.getMetrics(); result = new MetricRegistry(); bitContext.getAllocator(); result = new TopLevelAllocator(); bitContext.getOperatorCreatorRegistry(); result = new OperatorCreatorRegistry(c); bitContext.getConfig(); result = c; } }; PhysicalPlanReader reader = new PhysicalPlanReader( c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance()); PhysicalPlan plan = reader.readPhysicalPlan( Files.toString( FileUtils.getResourceAsFile("/functions/testSubstringNegative.json"), Charsets.UTF_8)); FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); SimpleRootExec exec = new SimpleRootExec( ImplCreator.getExec( context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); while (exec.next()) { NullableVarCharVector c1 = exec.getValueVectorById( new SchemaPath("col3", ExpressionPosition.UNKNOWN), NullableVarCharVector.class); NullableVarCharVector.Accessor a1; a1 = c1.getAccessor(); int count = 0; for (int i = 0; i < c1.getAccessor().getValueCount(); i++) { if (!a1.isNull(i)) { NullableVarCharHolder holder = new NullableVarCharHolder(); a1.get(i, holder); // when offset is negative, substring return empty string. assertEquals("", holder.toString()); ++count; } } assertEquals(50, count); } if (context.getFailureCause() != null) { throw context.getFailureCause(); } assertTrue(!context.isFailed()); }
public WorkspaceSchemaFactory( DrillConfig drillConfig, PStoreProvider provider, FileSystemPlugin plugin, String schemaName, String storageEngineName, DrillFileSystem fileSystem, WorkspaceConfig config, List<FormatMatcher> formatMatchers) throws ExecutionSetupException, IOException { this.fs = fileSystem; this.plugin = plugin; this.drillConfig = drillConfig; this.config = config; this.mapper = drillConfig.getMapper(); this.fileMatchers = Lists.newArrayList(); this.dirMatchers = Lists.newArrayList(); this.storageEngineName = storageEngineName; this.schemaName = schemaName; // setup cache if (storageEngineName == null) { this.knownViews = null; // this.knownPaths = null; } else { this.knownViews = provider.getPStore( PStoreConfig // .newJacksonBuilder(drillConfig.getMapper(), String.class) // .name(Joiner.on('.').join("storage.views", storageEngineName, schemaName)) // .build()); // this.knownPaths = provider.getPTable(PTableConfig // // .newJacksonBuilder(drillConfig.getMapper(), String.class) // // .name(Joiner.on('.').join("storage.cache", storageEngineName, schemaName)) // // .build()); } for (FormatMatcher m : formatMatchers) { if (m.supportDirectoryReads()) { dirMatchers.add(m); } fileMatchers.add(m); } }
public <T> T getWith(DrillConfig config, Class<T> c) { try { // logger.debug("Read tree {}", root); return config.getMapper().treeToValue(root, c); } catch (JsonProcessingException e) { throw new LogicalPlanParsingException( String.format( "Failure while trying to convert late bound json options to type of %s. Reference was originally located at line %d, column %d.", c.getCanonicalName(), location.getLineNr(), location.getColumnNr()), e); } }
@Test public void project( @Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Exception { new NonStrictExpectations() { { bitContext.getMetrics(); result = new MetricRegistry("test"); bitContext.getAllocator(); result = BufferAllocator.getAllocator(c); } }; PhysicalPlanReader reader = new PhysicalPlanReader( c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance()); PhysicalPlan plan = reader.readPhysicalPlan( Files.toString(FileUtils.getResourceAsFile("/project/test1.json"), Charsets.UTF_8)); FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); FragmentContext context = new FragmentContext( bitContext, FragmentHandle.getDefaultInstance(), connection, null, registry); SimpleRootExec exec = new SimpleRootExec( ImplCreator.getExec( context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); while (exec.next()) { BigIntVector c1 = exec.getValueVectorById( new SchemaPath("col1", ExpressionPosition.UNKNOWN), BigIntVector.class); BigIntVector c2 = exec.getValueVectorById( new SchemaPath("col2", ExpressionPosition.UNKNOWN), BigIntVector.class); int x = 0; BigIntVector.Accessor a1, a2; a1 = c1.getAccessor(); a2 = c2.getAccessor(); for (int i = 0; i < c1.getAccessor().getValueCount(); i++) { assertEquals(a1.get(i) + 1, a2.get(i)); x += a1.get(i); } System.out.println(x); } }
@Test public void testAllocators() throws Exception { // Setup a drillbit (initializes a root allocator) final DrillConfig config = DrillConfig.create(TEST_CONFIGURATIONS); final RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet(); final Drillbit bit = new Drillbit(config, serviceSet); bit.run(); final DrillbitContext bitContext = bit.getContext(); FunctionImplementationRegistry functionRegistry = bitContext.getFunctionImplementationRegistry(); StoragePluginRegistry storageRegistry = new StoragePluginRegistry(bitContext); // Create a few Fragment Contexts BitControl.PlanFragment.Builder pfBuilder1 = BitControl.PlanFragment.newBuilder(); pfBuilder1.setMemInitial(1500000); BitControl.PlanFragment pf1 = pfBuilder1.build(); BitControl.PlanFragment.Builder pfBuilder2 = BitControl.PlanFragment.newBuilder(); pfBuilder2.setMemInitial(500000); BitControl.PlanFragment pf2 = pfBuilder1.build(); FragmentContext fragmentContext1 = new FragmentContext(bitContext, pf1, null, functionRegistry); FragmentContext fragmentContext2 = new FragmentContext(bitContext, pf2, null, functionRegistry); // Get a few physical operators. Easiest way is to read a physical plan. PhysicalPlanReader planReader = new PhysicalPlanReader( config, config.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance(), storageRegistry); PhysicalPlan plan = planReader.readPhysicalPlan( Files.toString(FileUtils.getResourceAsFile(planFile), Charsets.UTF_8)); List<PhysicalOperator> physicalOperators = plan.getSortedOperators(); Iterator<PhysicalOperator> physicalOperatorIterator = physicalOperators.iterator(); PhysicalOperator physicalOperator1 = physicalOperatorIterator.next(); PhysicalOperator physicalOperator2 = physicalOperatorIterator.next(); PhysicalOperator physicalOperator3 = physicalOperatorIterator.next(); PhysicalOperator physicalOperator4 = physicalOperatorIterator.next(); PhysicalOperator physicalOperator5 = physicalOperatorIterator.next(); PhysicalOperator physicalOperator6 = physicalOperatorIterator.next(); // Create some bogus Operator profile defs and stats to create operator contexts OpProfileDef def; OperatorStats stats; // Use some bogus operator type to create a new operator context. def = new OpProfileDef( physicalOperator1.getOperatorId(), UserBitShared.CoreOperatorType.MOCK_SUB_SCAN_VALUE, OperatorContext.getChildCount(physicalOperator1)); stats = fragmentContext1.getStats().getOperatorStats(def, fragmentContext1.getAllocator()); // Add a couple of Operator Contexts // Initial allocation = 1000000 bytes for all operators OperatorContext oContext11 = fragmentContext1.newOperatorContext(physicalOperator1, true); DrillBuf b11 = oContext11.getAllocator().buffer(1000000); OperatorContext oContext12 = fragmentContext1.newOperatorContext(physicalOperator2, stats, true); DrillBuf b12 = oContext12.getAllocator().buffer(500000); OperatorContext oContext21 = fragmentContext1.newOperatorContext(physicalOperator3, true); def = new OpProfileDef( physicalOperator4.getOperatorId(), UserBitShared.CoreOperatorType.TEXT_WRITER_VALUE, OperatorContext.getChildCount(physicalOperator4)); stats = fragmentContext2.getStats().getOperatorStats(def, fragmentContext2.getAllocator()); OperatorContext oContext22 = fragmentContext2.newOperatorContext(physicalOperator4, stats, true); DrillBuf b22 = oContext22.getAllocator().buffer(2000000); // New Fragment begins BitControl.PlanFragment.Builder pfBuilder3 = BitControl.PlanFragment.newBuilder(); pfBuilder3.setMemInitial(1000000); BitControl.PlanFragment pf3 = pfBuilder3.build(); FragmentContext fragmentContext3 = new FragmentContext(bitContext, pf3, null, functionRegistry); // New fragment starts an operator that allocates an amount within the limit def = new OpProfileDef( physicalOperator5.getOperatorId(), UserBitShared.CoreOperatorType.UNION_VALUE, OperatorContext.getChildCount(physicalOperator5)); stats = fragmentContext3.getStats().getOperatorStats(def, fragmentContext3.getAllocator()); OperatorContext oContext31 = fragmentContext3.newOperatorContext(physicalOperator5, stats, true); DrillBuf b31a = oContext31.getAllocator().buffer(200000); // Previously running operator completes b22.release(); ((AutoCloseable) oContext22).close(); // Fragment 3 asks for more and fails boolean outOfMem = false; try { DrillBuf b31b = oContext31.getAllocator().buffer(4400000); if (b31b != null) { b31b.release(); } else { outOfMem = true; } } catch (Exception e) { outOfMem = true; } assertEquals(true, (boolean) outOfMem); // Operator is Exempt from Fragment limits. Fragment 3 asks for more and succeeds outOfMem = false; OperatorContext oContext32 = fragmentContext3.newOperatorContext(physicalOperator6, false); DrillBuf b32 = null; try { b32 = oContext32.getAllocator().buffer(4400000); } catch (Exception e) { outOfMem = true; } finally { if (b32 != null) { b32.release(); } else { outOfMem = true; } closeOp(oContext32); } assertEquals(false, (boolean) outOfMem); b11.release(); closeOp(oContext11); b12.release(); closeOp(oContext12); closeOp(oContext21); b31a.release(); closeOp(oContext31); fragmentContext1.close(); fragmentContext2.close(); fragmentContext3.close(); bit.close(); serviceSet.close(); }
public <T> T getListWith(DrillConfig config, TypeReference<T> t) throws IOException { ObjectMapper mapper = config.getMapper(); return mapper.treeAsTokens(root).readValueAs(t); // return mapper.treeToValue(root, mapper.getTypeFactory().constructCollectionType(List.class, // c)); }
@Test public void sortOneKeyAscending( @Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable { new NonStrictExpectations() { { bitContext.getMetrics(); result = new MetricRegistry(); bitContext.getAllocator(); result = new TopLevelAllocator(); bitContext.getOperatorCreatorRegistry(); result = new OperatorCreatorRegistry(c); bitContext.getConfig(); result = c; bitContext.getCompiler(); result = CodeCompiler.getTestCompiler(c); } }; final PhysicalPlanReader reader = new PhysicalPlanReader( c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance()); final PhysicalPlan plan = reader.readPhysicalPlan( Files.toString(FileUtils.getResourceAsFile("/sort/one_key_sort.json"), Charsets.UTF_8)); final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c); final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry); final SimpleRootExec exec = new SimpleRootExec( ImplCreator.getExec( context, (FragmentRoot) plan.getSortedOperators(false).iterator().next())); int previousInt = Integer.MIN_VALUE; int recordCount = 0; int batchCount = 0; while (exec.next()) { batchCount++; final IntVector c1 = exec.getValueVectorById( new SchemaPath("blue", ExpressionPosition.UNKNOWN), IntVector.class); final IntVector c2 = exec.getValueVectorById( new SchemaPath("green", ExpressionPosition.UNKNOWN), IntVector.class); final IntVector.Accessor a1 = c1.getAccessor(); final IntVector.Accessor a2 = c2.getAccessor(); for (int i = 0; i < c1.getAccessor().getValueCount(); i++) { recordCount++; assertTrue(previousInt <= a1.get(i)); previousInt = a1.get(i); assertEquals(previousInt, a2.get(i)); } } System.out.println(String.format("Sorted %,d records in %d batches.", recordCount, batchCount)); if (context.getFailureCause() != null) { throw context.getFailureCause(); } assertTrue(!context.isFailed()); }