gora-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GORA-535) Add a data store for Apache Ignite
Date Sun, 15 Jul 2018 07:19:01 GMT

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

ASF GitHub Bot commented on GORA-535:
-------------------------------------

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

    https://github.com/apache/gora/pull/134#discussion_r202521701
  
    --- Diff: gora-ignite/src/main/java/org/apache/gora/ignite/utils/IgniteSQLBuilder.java
---
    @@ -0,0 +1,238 @@
    +/**
    + * 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.gora.ignite.utils;
    +
    +import avro.shaded.com.google.common.collect.Lists;
    +import java.sql.PreparedStatement;
    +import java.sql.SQLException;
    +import java.text.MessageFormat;
    +import java.util.ArrayList;
    +import java.util.List;
    +import java.util.Locale;
    +import java.util.Map;
    +import java.util.Map.Entry;
    +import java.util.Set;
    +import org.apache.gora.ignite.store.Column;
    +import org.apache.gora.ignite.store.IgniteMapping;
    +
    +/**
    + *
    + * SQL Builder utility for Ignite.
    + */
    +public class IgniteSQLBuilder {
    +
    +  private static String format(String pattern, Object... args) {
    +    MessageFormat messageFormat = new MessageFormat(pattern, Locale.getDefault());
    +    return messageFormat.format(args);
    +  }
    +
    +  public static String tableExists(String tableName) {
    +    return format("SELECT * FROM {0} LIMIT 0", tableName);
    +  }
    +
    +  public static String createTable(IgniteMapping mapping) {
    +    StringBuilder sqlBuilder = new StringBuilder();
    +    sqlBuilder.append("CREATE TABLE ");
    +    sqlBuilder.append(mapping.getTableName());
    +    sqlBuilder.append("(");
    +    ArrayList<Column> fieldsList = Lists.newArrayList(mapping.getPrimaryKey());
    +    fieldsList.addAll(Lists.newArrayList(mapping.getFields().values()));
    +    for (Column aColumn : fieldsList) {
    +      String name = aColumn.getName();
    +      Column.FieldType dataType = aColumn.getDataType();
    +      sqlBuilder.append(name).append(" ").append(dataType.toString()).append(",");
    +    }
    +    sqlBuilder.append("PRIMARY KEY ");
    +    sqlBuilder.append("(");
    +    for (int i = 0; i < mapping.getPrimaryKey().size(); i++) {
    +      sqlBuilder.append(mapping.getPrimaryKey().get(i).getName());
    +      sqlBuilder.append(i == mapping.getPrimaryKey().size() - 1 ? "" : ",");
    +    }
    +    sqlBuilder.append(")");
    +    sqlBuilder.append(");");
    +    return sqlBuilder.toString();
    +  }
    +
    +  public static String dropTable(String tableName) {
    +    return format("DROP TABLE IF EXISTS {0} ;", tableName);
    +  }
    +
    +  public static String baseInsertStatement(IgniteMapping mapping, Map<Column, Object>
data) {
    +    StringBuilder sqlBuilder = new StringBuilder();
    +    sqlBuilder.append("MERGE INTO ");
    +    sqlBuilder.append(mapping.getTableName());
    +    sqlBuilder.append(" (");
    +    List<Entry<Column, Object>> list = new ArrayList<>(data.entrySet());
    +    for (int i = 0; i < list.size(); i++) {
    +      sqlBuilder.append(list.get(i).getKey().getName());
    +      sqlBuilder.append(i == list.size() - 1 ? "" : ",");
    +    }
    +    sqlBuilder.append(")");
    +    sqlBuilder.append(" VALUES ");
    +    sqlBuilder.append(" (");
    +    for (int i = 0; i < list.size(); i++) {
    +      sqlBuilder.append("?");
    +      sqlBuilder.append(i == list.size() - 1 ? "" : ",");
    +    }
    +    sqlBuilder.append(" )");
    +    return sqlBuilder.toString();
    +  }
    +
    +  public static void fillInsertStatement(PreparedStatement st, Map<Column, Object>
data) throws SQLException {
    +    List<Entry<Column, Object>> list = new ArrayList<>(data.entrySet());
    +    for (int i = 0; i < list.size(); i++) {
    +      int j = i + 1;
    +      st.setObject(j, list.get(i).getValue());
    +    }
    +  }
    +
    +  public static String delete(IgniteMapping mapping) {
    +    StringBuilder sqlBuilder = new StringBuilder();
    +    sqlBuilder.append("DELETE FROM ");
    +    sqlBuilder.append(mapping.getTableName());
    +    sqlBuilder.append(" WHERE ");
    +    for (int i = 0; i < mapping.getPrimaryKey().size(); i++) {
    +      sqlBuilder.append(mapping.getPrimaryKey().get(i).getName());
    +      sqlBuilder.append("= ? ");
    +      sqlBuilder.append(i == mapping.getPrimaryKey().size() - 1 ? "" : " AND ");
    +    }
    +    return sqlBuilder.toString();
    +  }
    +
    +  public static void fillDeleteStatement(PreparedStatement st, IgniteMapping mapping,
Object... data) throws SQLException {
    +    assert mapping.getPrimaryKey().size() == data.length;
    +    for (int i = 0; i < mapping.getPrimaryKey().size(); i++) {
    +      int j = i + 1;
    +      st.setObject(j, data[i]);
    +    }
    +  }
    +
    +  public static String selectGet(IgniteMapping mapping, List<String> fields) {
    +    StringBuilder sqlBuilder = new StringBuilder();
    +    sqlBuilder.append("SELECT ");
    +    for (int i = 0; i < fields.size(); i++) {
    +      sqlBuilder.append(fields.get(i));
    +      sqlBuilder.append(i == fields.size() - 1 ? "" : " , ");
    +    }
    +    sqlBuilder.append(" FROM ");
    +    sqlBuilder.append(mapping.getTableName());
    +    sqlBuilder.append(" WHERE ");
    +    for (int i = 0; i < mapping.getPrimaryKey().size(); i++) {
    +      sqlBuilder.append(mapping.getPrimaryKey().get(i).getName());
    +      sqlBuilder.append("= ? ");
    +      sqlBuilder.append(i == mapping.getPrimaryKey().size() - 1 ? "" : " AND ");
    +    }
    +    return sqlBuilder.toString();
    +  }
    +
    +  public static void fillSelectStatement(PreparedStatement st, IgniteMapping mapping,
Object... data) throws SQLException {
    +    assert mapping.getPrimaryKey().size() == data.length;
    +    for (int i = 0; i < mapping.getPrimaryKey().size(); i++) {
    +      int j = i + 1;
    +      st.setObject(j, data[i]);
    +    }
    +  }
    +
    +  public static String selectQuery(IgniteMapping mapping, List<String> ifields)
{
    +    List<String> fields = new ArrayList<>();
    +    for (Column c : mapping.getPrimaryKey()) {
    +      fields.add(c.getName());
    +    }
    +    fields.addAll(ifields);
    +    StringBuilder sqlBuilder = new StringBuilder();
    +    sqlBuilder.append("SELECT ");
    +    for (int i = 0; i < fields.size(); i++) {
    +      sqlBuilder.append(fields.get(i));
    +      sqlBuilder.append(i == fields.size() - 1 ? "" : " , ");
    +    }
    +    sqlBuilder.append(" FROM ");
    +    sqlBuilder.append(mapping.getTableName());
    +    return sqlBuilder.toString();
    +  }
    +
    +  public static String deleteQuery(IgniteMapping mapping) {
    +    StringBuilder sqlBuilder = new StringBuilder();
    +    sqlBuilder.append("DELETE FROM ");
    +    sqlBuilder.append(mapping.getTableName());
    +    return sqlBuilder.toString();
    +  }
    +
    +  public static String deleteQueryFields(IgniteMapping mapping, List<String> lsFields)
{
    +    StringBuilder sqlBuilder = new StringBuilder();
    +    sqlBuilder.append("UPDATE ");
    +    sqlBuilder.append(mapping.getTableName());
    +    if (!lsFields.isEmpty()) {
    +      sqlBuilder.append(" SET ");
    +    }
    +    for (int i = 0; i < lsFields.size(); i++) {
    +      sqlBuilder.append(lsFields.get(i));
    +      sqlBuilder.append(" = null");
    +      sqlBuilder.append(i == lsFields.size() - 1 ? "" : " , ");
    +    }
    +    return sqlBuilder.toString();
    +  }
    +
    +  public static String selectQueryWhere(IgniteMapping mapping, Object sk, Object ek,
long limit) {
    +    //composite keys pending
    +    assert mapping.getPrimaryKey().size() == 1;
    +    String keycolumn = mapping.getPrimaryKey().get(0).getName();
    +    StringBuilder sqlBuilder = new StringBuilder();
    +    if (sk != null || ek != null) {
    +      sqlBuilder.append(" WHERE ");
    +      if (sk != null && ek != null && sk.equals(ek)) {
    +        sqlBuilder.append(keycolumn);
    +        sqlBuilder.append("= ?");
    +      } else {
    +        if (sk != null) {
    +          sqlBuilder.append(keycolumn);
    +          sqlBuilder.append(">= ?");
    +        }
    +        if (sk != null && ek != null) {
    +          sqlBuilder.append(" AND ");
    +        }
    +        if (ek != null) {
    +          sqlBuilder.append(keycolumn);
    +          sqlBuilder.append("<= ?");
    +        }
    +      }
    +    }
    +    if (limit > 0) {
    +      sqlBuilder.append(" LIMIT " + limit);
    +    }
    +    return sqlBuilder.toString();
    +  }
    +
    +  public static void fillSelectQuery(PreparedStatement st, Object sk, Object ek) throws
SQLException {
    --- End diff --
    
    Shall we add Java docs to all the public methods? It would be better if the variable names
can be meaningful.


> Add a data store for Apache Ignite 
> -----------------------------------
>
>                 Key: GORA-535
>                 URL: https://issues.apache.org/jira/browse/GORA-535
>             Project: Apache Gora
>          Issue Type: New Feature
>            Reporter: Nishadi Kirielle
>            Priority: Major
>              Labels: gsoc2018
>
> Currently, Gora has support for persisting objects to various database models such as
Apache Hbase, Apache Cassandra and much more. [1] This project aims to extend its capability
to provide support for Apache Ignite database.
> Apache Ignite is a distributed database, caching and processing platform.[2] 
> [1]. [http://gora.apache.org/] 
> [2] . [https://ignite.apache.org/]
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message