Github user kaspersorensen commented on a diff in the pull request:

    https://github.com/apache/metamodel/pull/85#discussion_r49314038
  
    --- Diff: core/src/main/java/org/apache/metamodel/query/ConcatFunction.java 
---
    @@ -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
    + *
    + *   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.metamodel.query;
    +
    +import org.apache.metamodel.data.Row;
    +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 --
    
    What I mean is that a few lines lower, starting with the ```if``` and 
eventually hitting the ```getColumnValueFromRow``` (line 48) the parameter is 
treated only as a string. But what would be more natural to me is to check what 
type the parameter is. I think the parameter will already be a SelectItem here 
actually, but it's being changed into a string via the ```toString()``` call 
and then converted/resolved into a column by the ```getColumnValueFromRow``` 
call. It would be way better (IMO) to have something like:
    
    ```
    final String valueToConcat;
    if (parameter instanceof SelectItem) {
      valueToConcat = row.getValue((SelectItem)parameter);
    } else if (parameter instanceof Column) {
      valueToConcat = row.getValue((Column)parameter);
    } else {
      valueToConcat = parameter;
    }
    strBuilder.append(valueToConcat);
    ```
    
    And then you can delete the complete ```getColumnValueFromRow``` method 
which is just making things quite complex I think.


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

Reply via email to