[ 
https://issues.apache.org/jira/browse/METAMODEL-18?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14156733#comment-14156733
 ] 

ASF GitHub Bot commented on METAMODEL-18:
-----------------------------------------

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

    https://github.com/apache/incubator-metamodel/pull/2#discussion_r18351184
  
    --- Diff: 
cassandra/src/main/java/org/apache/metamodel/cassandra/CassandraDBUtils.java ---
    @@ -0,0 +1,80 @@
    +/**
    + * 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.cassandra;
    +
    +import com.datastax.driver.core.ColumnDefinitions;
    +import com.datastax.driver.core.DataType;
    +import org.apache.metamodel.data.DataSetHeader;
    +import org.apache.metamodel.data.DefaultRow;
    +import org.apache.metamodel.data.Row;
    +import org.apache.metamodel.query.SelectItem;
    +
    +/**
    + * A utility class for Cassandra module.
    + * 
    + * @author Alberto Rodriguez
    + */
    +public class CassandraDBUtils {
    +
    +    /**
    +     * Converts a Cassandra Row data object {@link 
com.datastax.driver.core.Row}
    +     * into MetaModel {@link org.apache.metamodel.data.Row}.
    +     *
    +     * @param dbObject a Cassandra object storing data.
    +     * @param header a header describing the columns of the data stored.
    +     * @return the MetaModel {@link org.apache.metamodel.data.Row} result 
object.
    +     */
    +    public static Row toRow(com.datastax.driver.core.Row dbObject, 
DataSetHeader header) {
    +
    +        if (dbObject == null) {
    +            return null;
    +        }
    +
    +        final int size = header.size();
    +
    +        final Object[] values = new Object[size];
    +        for (int i = 0; i < values.length; i++) {
    +            final SelectItem selectItem = header.getSelectItem(i);
    +            final String key = selectItem.getColumn().getName();
    +            values[i] = getColumnValue(key, dbObject);
    +        }
    +        return new DefaultRow(header, values);
    +    }
    +
    +    private static Object getColumnValue(String columnName, 
com.datastax.driver.core.Row row) {
    +        ColumnDefinitions columns = row.getColumnDefinitions();
    +        DataType columnType = columns.getType(columnName);
    +        switch (columnType.getName()) {
    +            case BIGINT: return row.getVarint(columnName);
    +            case BOOLEAN: return row.getBool(columnName);
    +            case DECIMAL: return row.getDecimal(columnName);
    +            case DOUBLE: return row.getDouble(columnName);
    +            case FLOAT: return row.getFloat(columnName);
    +            case INET: return row.getInet(columnName);
    +            case INT: return row.getInt(columnName);
    +            case UUID: return row.getUUID(columnName);
    --- End diff --
    
    Here we return a UUID instance, while the ColumnType will be STRING. I 
suggest we create a UUID ColumnType so that the value corresponds to the 
expected type. The same principle applies probably to other column types ... 
Set, Map, Inet and more.


> Cassandra DB support for MetaModel
> ----------------------------------
>
>                 Key: METAMODEL-18
>                 URL: https://issues.apache.org/jira/browse/METAMODEL-18
>             Project: Metamodel
>          Issue Type: New Feature
>            Reporter: Kasper Sørensen
>            Priority: Critical
>
> A new module for MetaModel, providing support for Cassandra.
> Note that Cassandra in many respects is similar to HBase, and we might run 
> into some of the same issues. Check METAMODEL-13 for our HBase module JIRA 
> issue.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to