Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id E86A7200CD3 for ; Fri, 14 Jul 2017 00:21:22 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id E6D1F16CFF9; Thu, 13 Jul 2017 22:21:22 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 39EDF16CFF6 for ; Fri, 14 Jul 2017 00:21:22 +0200 (CEST) Received: (qmail 54972 invoked by uid 500); 13 Jul 2017 22:21:18 -0000 Mailing-List: contact dev-help@drill.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@drill.apache.org Delivered-To: mailing list dev@drill.apache.org Received: (qmail 53861 invoked by uid 99); 13 Jul 2017 22:21:17 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Jul 2017 22:21:17 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2330AF5514; Thu, 13 Jul 2017 22:21:17 +0000 (UTC) From: Ben-Zvi To: dev@drill.apache.org Reply-To: dev@drill.apache.org References: In-Reply-To: Subject: [GitHub] drill pull request #860: DRILL-5601: Rollup of external sort fixes and impro... Content-Type: text/plain Message-Id: <20170713222117.2330AF5514@git1-us-west.apache.org> Date: Thu, 13 Jul 2017 22:21:17 +0000 (UTC) archived-at: Thu, 13 Jul 2017 22:21:23 -0000 Github user Ben-Zvi commented on a diff in the pull request: https://github.com/apache/drill/pull/860#discussion_r127067063 --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/record/SmartAllocationHelper.java --- @@ -0,0 +1,156 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.drill.exec.record; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.drill.exec.vector.AllocationHelper; +import org.apache.drill.exec.vector.ValueVector; +import org.apache.drill.exec.vector.complex.AbstractMapVector; +import org.apache.drill.exec.vector.complex.RepeatedMapVector; + +/** + * Prototype mechanism to allocate vectors based on expected + * data sizes. This version uses a name-based map of fields + * to sizes. Better to represent the batch structurally and + * simply iterate over the schema rather than doing a per-field + * lookup. But, the mechanisms needed to do the efficient solution + * don't exist yet. + */ + +public class SmartAllocationHelper { + + public static class AllocationHint { + public final int entryWidth; + public final int elementCount; + + private AllocationHint(int width, int elements) { + entryWidth = width; + elementCount = elements; + } + + @Override + public String toString() { + StringBuilder buf = new StringBuilder() --- End diff -- This whole method can be written in only 4 lines of code \: if ( entryWidth > 0 && elementCount > 0 ) { return String.format("{width=%d, elements=%d}",entryWidth,entryCount); } if ( entryWidth > 0 ) { return String.format("{width=%d}",entryWidth); } if ( elementCount > 0 ) { return String.format("{elements=%d}",entryCount); } return String.format("{}"); or String ew = ( entryWidth > 0 ) ? String.format("width=%d",entryWidth) : ""; String comma = ( entryWidth > 0 && elementCount > 0 ) ? ", " : ""; String ec = ( elementCount > 0 ) ? String.format("elements=%d",entryCount) : ""; return "{" + ew + comma + ec + "}" ; The above can even be pushed into a single line !!! A la APL :-) --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---