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

    https://github.com/apache/tajo/pull/232#discussion_r20343179
  
    --- Diff: 
tajo-storage/src/main/java/org/apache/tajo/storage/hbase/ColumnMapping.java ---
    @@ -0,0 +1,239 @@
    +/**
    + * 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.tajo.storage.hbase;
    +
    +import org.apache.hadoop.hbase.util.Bytes;
    +import org.apache.tajo.catalog.Schema;
    +import org.apache.tajo.catalog.TableMeta;
    +import org.apache.tajo.util.BytesUtils;
    +
    +import java.io.IOException;
    +import java.util.ArrayList;
    +import java.util.List;
    +
    +public class ColumnMapping {
    +  public static final String KEY_COLUMN_MAPPING = "key";
    +  public static final String VALUE_COLUMN_MAPPING = "value";
    +
    +  private TableMeta tableMeta;
    +  private Schema schema;
    +  private char rowKeyDelimiter;
    +
    +  private String hbaseTableName;
    +
    +  private int[] rowKeyFieldIndexes;
    +  private boolean[] isRowKeyMappings;
    +  private boolean[] isBinaryColumns;
    +  private boolean[] isColumnKeys;
    +  private boolean[] isColumnValues;
    +
    +  // schema order -> 0: cf name, 1: column name -> name bytes
    +  private byte[][][] mappingColumns;
    +
    +  private int numRowKeys;
    +
    +  public ColumnMapping(Schema schema, TableMeta tableMeta) throws 
IOException {
    +    this.schema = schema;
    +    this.tableMeta = tableMeta;
    +
    +    init();
    +  }
    +
    +  public void init() throws IOException {
    +    hbaseTableName = 
tableMeta.getOption(HBaseStorageManager.META_TABLE_KEY);
    +    String delim = 
tableMeta.getOption(HBaseStorageManager.META_ROWKEY_DELIMITER, "").trim();
    +    if (delim.length() > 0) {
    +      rowKeyDelimiter = delim.charAt(0);
    +    }
    +    isRowKeyMappings = new boolean[schema.size()];
    +    rowKeyFieldIndexes = new int[schema.size()];
    +    isBinaryColumns = new boolean[schema.size()];
    +    isColumnKeys = new boolean[schema.size()];
    +    isColumnValues = new boolean[schema.size()];
    +
    +    mappingColumns = new byte[schema.size()][][];
    +
    +    for (int i = 0; i < schema.size(); i++) {
    +      rowKeyFieldIndexes[i] = -1;
    +    }
    +
    +    String columnMapping = 
tableMeta.getOption(HBaseStorageManager.META_COLUMNS_KEY, "");
    +    if (columnMapping == null || columnMapping.isEmpty()) {
    +      throw new IOException("'columns' property is required.");
    +    }
    +
    +    String[] columnMappingTokens = columnMapping.split(",");
    +
    +    if (columnMappingTokens.length != schema.getColumns().size()) {
    +      throw new IOException("The number of mapped HBase columns is great 
than the number of Tajo table columns");
    +    }
    +
    +    int index = 0;
    +    for (String eachToken: columnMappingTokens) {
    +      mappingColumns[index] = new byte[2][];
    +
    +      byte[][] mappingTokens = 
BytesUtils.splitPreserveAllTokens(eachToken.trim().getBytes(), ':');
    +
    +      if (mappingTokens.length == 3) {
    --- End diff --
    
    GlobalEngine calls StorageManager.beforeInsertOrCATS() before running a 
insertion or creation query. In beforeInsertOrCATS() method ColumnMapping is 
checked.


---
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