Java Code Examples for org.apache.hive.hcatalog.data.HCatRecord#set()

The following examples show how to use org.apache.hive.hcatalog.data.HCatRecord#set() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FactDistinctColumnsMapperTest.java    From kylin with Apache License 2.0 5 votes vote down vote up
@Test
public void testMapper() throws IOException {
    Configuration configuration = mapDriver.getConfiguration();
    configuration.set(BatchConstants.CFG_STATISTICS_SAMPLING_PERCENT, "100");
    configuration.set(BatchConstants.CFG_CUBE_NAME, "test_kylin_cube_with_slr_1_new_segment");
    configuration.set(BatchConstants.CFG_CUBE_SEGMENT_ID, "198va32a-a33e-4b69-83dd-0bb8b1f8c53b");
    HCatRecord value1 = new DefaultHCatRecord(11);
    value1.set(0, "2012-08-16");
    value1.set(1, "48027");
    value1.set(2, "0");
    value1.set(3, "Home & Garden");
    value1.set(4, "Cheese & Crackers");
    value1.set(5, "Cheese & Crackers");
    value1.set(6, "48027");
    value1.set(7, "16");
    value1.set(8, "10000010");
    value1.set(9, "204.28");
    value1.set(10, "5");
    mapDriver.addInput(new LongWritable(0), value1);

    List<Pair<SelfDefineSortableKey, Text>> result = mapDriver.run();
    int colsNeedDictSize = cubeDesc.getAllColumnsNeedDictionaryBuilt().size();
    int cuboidsCnt = cubeDesc.getAllCuboids().size();

    assertEquals(
            colsNeedDictSize + (cubeDesc.getRowkey().getRowKeyColumns().length - colsNeedDictSize) * 2 + cuboidsCnt,
            result.size());
}
 
Example 2
Source File: SqoopHCatImportHelper.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 4 votes vote down vote up
public HCatRecord convertToHCatRecord(SqoopRecord sqr) throws IOException,
  InterruptedException {
  try {
    // Loading of LOBs was delayed until we have a Context.
    sqr.loadLargeObjects(lobLoader);
  } catch (SQLException sqlE) {
    throw new IOException(sqlE);
  }
  if (colCount == -1) {
    colCount = sqr.getFieldMap().size();
  }

  Map<String, Object> fieldMap = sqr.getFieldMap();
  HCatRecord result = new DefaultHCatRecord(fieldCount);

  for (Map.Entry<String, Object> entry : fieldMap.entrySet()) {
    String key = entry.getKey();
    Object val = entry.getValue();
    String hfn = key.toLowerCase();
    boolean skip = false;
    if (staticPartitionKeys != null && staticPartitionKeys.length > 0) {
      for (int i = 0; i < staticPartitionKeys.length; ++i) {
        if (staticPartitionKeys[i].equals(hfn)) {
          skip = true;
          break;
        }
      }
    }
    if (skip) {
      continue;
    }
    HCatFieldSchema hfs = null;
    try {
      hfs = hCatFullTableSchema.get(hfn);
    } catch (Exception e) {
      throw new IOException("Unable to lookup " + hfn + " in the hcat schema");
    }
    if (debugHCatImportMapper) {
      LOG.debug("SqoopRecordVal: field = " + key + " Val " + val
        + " of type " + (val == null ? null : val.getClass().getName())
        + ", hcattype " + hfs.getTypeString());
    }
    Object hCatVal = toHCat(val, hfs);

    result.set(hfn, hCatFullTableSchema, hCatVal);
  }

  return result;
}