Search in sources :

Example 11 with LinkedHashSet

use of java.util.LinkedHashSet in project flink by apache.

the class FlinkAggregateExpandDistinctAggregatesRule method onMatch.

//~ Methods ----------------------------------------------------------------
public void onMatch(RelOptRuleCall call) {
    final Aggregate aggregate = call.rel(0);
    if (!aggregate.containsDistinctCall()) {
        return;
    }
    // Find all of the agg expressions. We use a LinkedHashSet to ensure
    // determinism.
    int nonDistinctCount = 0;
    int distinctCount = 0;
    int filterCount = 0;
    int unsupportedAggCount = 0;
    final Set<Pair<List<Integer>, Integer>> argLists = new LinkedHashSet<>();
    for (AggregateCall aggCall : aggregate.getAggCallList()) {
        if (aggCall.filterArg >= 0) {
            ++filterCount;
        }
        if (!aggCall.isDistinct()) {
            ++nonDistinctCount;
            if (!(aggCall.getAggregation() instanceof SqlCountAggFunction || aggCall.getAggregation() instanceof SqlSumAggFunction || aggCall.getAggregation() instanceof SqlMinMaxAggFunction)) {
                ++unsupportedAggCount;
            }
            continue;
        }
        ++distinctCount;
        argLists.add(Pair.of(aggCall.getArgList(), aggCall.filterArg));
    }
    Preconditions.checkState(argLists.size() > 0, "containsDistinctCall lied");
    // arguments then we can use a more efficient form.
    if (nonDistinctCount == 0 && argLists.size() == 1) {
        final Pair<List<Integer>, Integer> pair = Iterables.getOnlyElement(argLists);
        final RelBuilder relBuilder = call.builder();
        convertMonopole(relBuilder, aggregate, pair.left, pair.right);
        call.transformTo(relBuilder.build());
        return;
    }
    if (useGroupingSets) {
        rewriteUsingGroupingSets(call, aggregate, argLists);
        return;
    }
    // we can generate multi-phase aggregates
    if (// one distinct aggregate
    distinctCount == 1 && // no filter
    filterCount == 0 && // sum/min/max/count in non-distinct aggregate
    unsupportedAggCount == 0 && nonDistinctCount > 0) {
        // one or more non-distinct aggregates
        final RelBuilder relBuilder = call.builder();
        convertSingletonDistinct(relBuilder, aggregate, argLists);
        call.transformTo(relBuilder.build());
        return;
    }
    // Create a list of the expressions which will yield the final result.
    // Initially, the expressions point to the input field.
    final List<RelDataTypeField> aggFields = aggregate.getRowType().getFieldList();
    final List<RexInputRef> refs = new ArrayList<>();
    final List<String> fieldNames = aggregate.getRowType().getFieldNames();
    final ImmutableBitSet groupSet = aggregate.getGroupSet();
    final int groupAndIndicatorCount = aggregate.getGroupCount() + aggregate.getIndicatorCount();
    for (int i : Util.range(groupAndIndicatorCount)) {
        refs.add(RexInputRef.of(i, aggFields));
    }
    // Aggregate the original relation, including any non-distinct aggregates.
    final List<AggregateCall> newAggCallList = new ArrayList<>();
    int i = -1;
    for (AggregateCall aggCall : aggregate.getAggCallList()) {
        ++i;
        if (aggCall.isDistinct()) {
            refs.add(null);
            continue;
        }
        refs.add(new RexInputRef(groupAndIndicatorCount + newAggCallList.size(), aggFields.get(groupAndIndicatorCount + i).getType()));
        newAggCallList.add(aggCall);
    }
    // In the case where there are no non-distinct aggregates (regardless of
    // whether there are group bys), there's no need to generate the
    // extra aggregate and join.
    final RelBuilder relBuilder = call.builder();
    relBuilder.push(aggregate.getInput());
    int n = 0;
    if (!newAggCallList.isEmpty()) {
        final RelBuilder.GroupKey groupKey = relBuilder.groupKey(groupSet, aggregate.indicator, aggregate.getGroupSets());
        relBuilder.aggregate(groupKey, newAggCallList);
        ++n;
    }
    // set of operands.
    for (Pair<List<Integer>, Integer> argList : argLists) {
        doRewrite(relBuilder, aggregate, n++, argList.left, argList.right, refs);
    }
    relBuilder.project(refs, fieldNames);
    call.transformTo(relBuilder.build());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) RelBuilder(org.apache.calcite.tools.RelBuilder) SqlMinMaxAggFunction(org.apache.calcite.sql.fun.SqlMinMaxAggFunction) ImmutableBitSet(org.apache.calcite.util.ImmutableBitSet) ArrayList(java.util.ArrayList) SqlCountAggFunction(org.apache.calcite.sql.fun.SqlCountAggFunction) AggregateCall(org.apache.calcite.rel.core.AggregateCall) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) SqlSumAggFunction(org.apache.calcite.sql.fun.SqlSumAggFunction) RexInputRef(org.apache.calcite.rex.RexInputRef) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) ImmutableIntList(org.apache.calcite.util.ImmutableIntList) List(java.util.List) Aggregate(org.apache.calcite.rel.core.Aggregate) LogicalAggregate(org.apache.calcite.rel.logical.LogicalAggregate) Pair(org.apache.calcite.util.Pair)

Example 12 with LinkedHashSet

use of java.util.LinkedHashSet in project groovy by apache.

the class SourceExtensionHandler method getRegisteredExtensions.

public static Set<String> getRegisteredExtensions(ClassLoader loader) {
    Set<String> extensions = new LinkedHashSet<String>();
    extensions.add("groovy");
    try {
        Enumeration<URL> globalServices = loader.getResources("META-INF/services/org.codehaus.groovy.source.Extensions");
        while (globalServices.hasMoreElements()) {
            BufferedReader svcIn = null;
            URL service = globalServices.nextElement();
            try {
                svcIn = new BufferedReader(new InputStreamReader(service.openStream()));
                String extension = svcIn.readLine();
                while (extension != null) {
                    extension = extension.trim();
                    if (!extension.startsWith("#") && extension.length() > 0) {
                        extensions.add(extension);
                    }
                    extension = svcIn.readLine();
                }
            } catch (IOException ex) {
                throw new GroovyRuntimeException("IO Exception attempting to load registered source extension " + service.toExternalForm() + ". Exception: " + ex.toString());
            } finally {
                if (svcIn != null)
                    svcIn.close();
            }
        }
    } catch (IOException ex) {
        throw new GroovyRuntimeException("IO Exception getting registered source extensions. Exception: " + ex.toString());
    }
    return extensions;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) GroovyRuntimeException(groovy.lang.GroovyRuntimeException) IOException(java.io.IOException) URL(java.net.URL)

Example 13 with LinkedHashSet

use of java.util.LinkedHashSet in project hadoop by apache.

the class DNS method getIPs.

/**
   * Returns all the IPs associated with the provided interface, if any, in
   * textual form.
   * 
   * @param strInterface
   *            The name of the network interface or sub-interface to query
   *            (eg eth0 or eth0:0) or the string "default"
   * @param returnSubinterfaces
   *            Whether to return IPs associated with subinterfaces of
   *            the given interface
   * @return A string vector of all the IPs associated with the provided
   *         interface. The local host IP is returned if the interface
   *         name "default" is specified or there is an I/O error looking
   *         for the given interface.
   * @throws UnknownHostException
   *             If the given interface is invalid
   * 
   */
public static String[] getIPs(String strInterface, boolean returnSubinterfaces) throws UnknownHostException {
    if ("default".equals(strInterface)) {
        return new String[] { cachedHostAddress };
    }
    NetworkInterface netIf;
    try {
        netIf = NetworkInterface.getByName(strInterface);
        if (netIf == null) {
            netIf = getSubinterface(strInterface);
        }
    } catch (SocketException e) {
        LOG.warn("I/O error finding interface " + strInterface + ": " + e.getMessage());
        return new String[] { cachedHostAddress };
    }
    if (netIf == null) {
        throw new UnknownHostException("No such interface " + strInterface);
    }
    // NB: Using a LinkedHashSet to preserve the order for callers
    // that depend on a particular element being 1st in the array.
    // For example, getDefaultIP always returns the first element.
    LinkedHashSet<InetAddress> allAddrs = new LinkedHashSet<InetAddress>();
    allAddrs.addAll(Collections.list(netIf.getInetAddresses()));
    if (!returnSubinterfaces) {
        allAddrs.removeAll(getSubinterfaceInetAddrs(netIf));
    }
    String[] ips = new String[allAddrs.size()];
    int i = 0;
    for (InetAddress addr : allAddrs) {
        ips[i++] = addr.getHostAddress();
    }
    return ips;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) SocketException(java.net.SocketException) UnknownHostException(java.net.UnknownHostException) NetworkInterface(java.net.NetworkInterface) InetAddress(java.net.InetAddress)

Example 14 with LinkedHashSet

use of java.util.LinkedHashSet in project groovy by apache.

the class ProxyGeneratorAdapter method visit.

@Override
public void visit(final int version, final int access, final String name, final String signature, final String superName, final String[] interfaces) {
    Set<String> interfacesSet = new LinkedHashSet<String>();
    if (interfaces != null)
        Collections.addAll(interfacesSet, interfaces);
    for (Class extraInterface : classList) {
        if (extraInterface.isInterface())
            interfacesSet.add(BytecodeHelper.getClassInternalName(extraInterface));
    }
    final boolean addGroovyObjectSupport = !GroovyObject.class.isAssignableFrom(superClass);
    if (addGroovyObjectSupport)
        interfacesSet.add("groovy/lang/GroovyObject");
    if (generateDelegateField) {
        classList.add(GeneratedGroovyProxy.class);
        interfacesSet.add("groovy/lang/GeneratedGroovyProxy");
    }
    super.visit(V1_5, ACC_PUBLIC, proxyName, signature, BytecodeHelper.getClassInternalName(superClass), interfacesSet.toArray(new String[interfacesSet.size()]));
    visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
    addDelegateFields();
    if (addGroovyObjectSupport) {
        createGroovyObjectSupport();
    }
    for (Class clazz : classList) {
        visitClass(clazz);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) GroovyClass(org.codehaus.groovy.tools.GroovyClass) GroovyObject(groovy.lang.GroovyObject)

Example 15 with LinkedHashSet

use of java.util.LinkedHashSet in project groovy by apache.

the class ProxyGeneratorAdapter method collectTraits.

private static void collectTraits(final Class clazz, final Set<ClassNode> traits) {
    Annotation annotation = clazz.getAnnotation(Trait.class);
    if (annotation != null) {
        ClassNode trait = ClassHelper.make(clazz);
        traits.add(trait.getPlainNodeReference());
        LinkedHashSet<ClassNode> selfTypes = new LinkedHashSet<ClassNode>();
        Traits.collectSelfTypes(trait, selfTypes, true, true);
        for (ClassNode selfType : selfTypes) {
            if (Traits.isTrait(selfType)) {
                traits.add(selfType.getPlainNodeReference());
            }
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ClassNode(org.codehaus.groovy.ast.ClassNode) Annotation(java.lang.annotation.Annotation)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)1252 ArrayList (java.util.ArrayList)241 Set (java.util.Set)154 HashSet (java.util.HashSet)128 HashMap (java.util.HashMap)115 File (java.io.File)102 IOException (java.io.IOException)97 Map (java.util.Map)97 Test (org.junit.Test)94 List (java.util.List)86 LinkedHashMap (java.util.LinkedHashMap)77 ProcessResult (org.asqatasun.entity.audit.ProcessResult)77 SourceCodeRemark (org.asqatasun.entity.audit.SourceCodeRemark)73 LinkedList (java.util.LinkedList)51 Iterator (java.util.Iterator)38 TreeSet (java.util.TreeSet)34 URL (java.net.URL)33 Collection (java.util.Collection)28 Feature (edu.illinois.cs.cogcomp.edison.features.Feature)24 ProcessRemark (org.asqatasun.entity.audit.ProcessRemark)23