metamodel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kaspersorensen <>
Subject [GitHub] metamodel pull request: METAMODEL-224 CONCAT function support
Date Fri, 08 Jan 2016 13:13:10 GMT
Github user kaspersorensen commented on a diff in the pull request:
    --- Diff: core/src/main/java/org/apache/metamodel/query/ ---
    @@ -0,0 +1,79 @@
    + * 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
    + *
    + *
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package org.apache.metamodel.query;
    +import org.apache.metamodel.schema.Column;
    +import org.apache.metamodel.schema.ColumnType;
    +import org.apache.metamodel.util.CollectionUtils;
    +import org.apache.metamodel.util.Predicate;
    +import java.util.List;
    + * Represents a function that concatenates values.
    + */
    +public final class ConcatFunction extends DefaultScalarFunction {
    +    @Override
    +    public Object evaluate(Row row, Object[] parameters, SelectItem operandItem) {
    +        SelectItem[] selectItems = row.getSelectItems();
    +        if (parameters.length == 0) {
    +            throw new IllegalArgumentException("Expecting some parameters to CONCAT function");
    +        }
    +        StringBuilder strBuilder = new StringBuilder();
    +        for (Object parameter: parameters) {
    +            String parameterAsString = parameter.toString();
    --- End diff --
    Wouldn't it make a lot of things easier if we decided to treat the parameters as SelectItems
instead of Strings? What I mean is - in this part of the code (and in ScalarFunctionRow) the
the changes made are quite involved because the parameters are of type String. But what if
we instead changed it so that the parameters are simply SelectItems. I guess that is also
what they _are_ from a (SQL) language perspective: ```CONCAT(foo, bar)``` would indicate that
"foo" and "bar" are select items, whereas ```CONCAT(foo, " ", bar)``` would be a select item,
a string and then a select item. I think we could greatly simplify the code if we work with
this model instead.

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 or file a JIRA ticket
with INFRA.

View raw message