Examples of DefaultHCatRecord


Examples of org.apache.hcatalog.data.DefaultHCatRecord

            objList.add(i);
            objList.add("strvalue" + i);
            objList.add("str2value" + i);

            writeRecords.add(new DefaultHCatRecord(objList));
        }

        Map<String, String> partitionMap = new HashMap<String, String>();
        partitionMap.put("part1", "p1value5");
        partitionMap.put("part0", "p0value5");

        runMRCreate(partitionMap, partitionColumns, writeRecords, 10, true);

        tableSchema = getTableSchema();

        //assert that c3 has got added to table schema
        assertEquals(5, tableSchema.getFields().size());
        assertEquals("c1", tableSchema.getFields().get(0).getName());
        assertEquals("c2", tableSchema.getFields().get(1).getName());
        assertEquals("c3", tableSchema.getFields().get(2).getName());
        assertEquals("part1", tableSchema.getFields().get(3).getName());
        assertEquals("part0", tableSchema.getFields().get(4).getName());

        //Test that changing column data type fails
        partitionMap.clear();
        partitionMap.put("part1", "p1value6");
        partitionMap.put("part0", "p0value6");

        partitionColumns = new ArrayList<HCatFieldSchema>();
        partitionColumns.add(HCatSchemaUtils.getHCatFieldSchema(new FieldSchema("c1", serdeConstants.INT_TYPE_NAME, "")));
        partitionColumns.add(HCatSchemaUtils.getHCatFieldSchema(new FieldSchema("c2", serdeConstants.INT_TYPE_NAME, "")));

        IOException exc = null;
        try {
            runMRCreate(partitionMap, partitionColumns, writeRecords, 20, true);
        } catch (IOException e) {
            exc = e;
        }

        assertTrue(exc != null);
        assertTrue(exc instanceof HCatException);
        assertEquals(ErrorType.ERROR_SCHEMA_TYPE_MISMATCH, ((HCatException) exc).getErrorType());

        //Test that partition key is not allowed in data
        partitionColumns = new ArrayList<HCatFieldSchema>();
        partitionColumns.add(HCatSchemaUtils.getHCatFieldSchema(new FieldSchema("c1", serdeConstants.INT_TYPE_NAME, "")));
        partitionColumns.add(HCatSchemaUtils.getHCatFieldSchema(new FieldSchema("c2", serdeConstants.STRING_TYPE_NAME, "")));
        partitionColumns.add(HCatSchemaUtils.getHCatFieldSchema(new FieldSchema("c3", serdeConstants.STRING_TYPE_NAME, "")));
        partitionColumns.add(HCatSchemaUtils.getHCatFieldSchema(new FieldSchema("part1", serdeConstants.STRING_TYPE_NAME, "")));

        List<HCatRecord> recordsContainingPartitionCols = new ArrayList<HCatRecord>(20);
        for (int i = 0; i < 20; i++) {
            List<Object> objList = new ArrayList<Object>();

            objList.add(i);
            objList.add("c2value" + i);
            objList.add("c3value" + i);
            objList.add("p1value6");

            recordsContainingPartitionCols.add(new DefaultHCatRecord(objList));
        }

        exc = null;
        try {
            runMRCreate(partitionMap, partitionColumns, recordsContainingPartitionCols, 20, true);
View Full Code Here

Examples of org.apache.hcatalog.data.DefaultHCatRecord

            objList.add(i);
            objList.add("co strvalue" + i);
            objList.add("co str2value" + i);

            writeRecords.add(new DefaultHCatRecord(objList));
        }

        Map<String, String> partitionMap = new HashMap<String, String>();
        partitionMap.put("part1", "p1value8");
        partitionMap.put("part0", "p0value8");

        Exception exc = null;
        try {
            runMRCreate(partitionMap, partitionColumns, writeRecords, 10, true);
        } catch (IOException e) {
            exc = e;
        }

        assertTrue(exc != null);
        assertTrue(exc instanceof HCatException);
        assertEquals(ErrorType.ERROR_SCHEMA_COLUMN_MISMATCH, ((HCatException) exc).getErrorType());


        partitionColumns = new ArrayList<HCatFieldSchema>();
        partitionColumns.add(HCatSchemaUtils.getHCatFieldSchema(new FieldSchema("c1", serdeConstants.INT_TYPE_NAME, "")));
        partitionColumns.add(HCatSchemaUtils.getHCatFieldSchema(new FieldSchema("c2", serdeConstants.STRING_TYPE_NAME, "")));

        writeRecords = new ArrayList<HCatRecord>();

        for (int i = 0; i < 10; i++) {
            List<Object> objList = new ArrayList<Object>();

            objList.add(i);
            objList.add("co strvalue" + i);

            writeRecords.add(new DefaultHCatRecord(objList));
        }

        runMRCreate(partitionMap, partitionColumns, writeRecords, 10, true);

        //Read should get 10 + 20 + 10 + 10 + 20 rows
View Full Code Here

Examples of org.apache.hcatalog.data.DefaultHCatRecord

        int i = 0;
        for (HCatFieldSchema fSchema : computedSchema.getFields()) {
            outgoing.add(getJavaObj(tuple.get(i++), fSchema));
        }
        try {
            writer.write(null, new DefaultHCatRecord(outgoing));
        } catch (InterruptedException e) {
            throw new BackendException("Error while writing tuple: " + tuple, PigHCatUtil.PIG_EXCEPTION_CODE, e);
        }
    }
View Full Code Here

Examples of org.apache.hive.hcatalog.data.DefaultHCatRecord

      age = value.get(1) == null ? null : (Integer) value.get(1);
      gpa = value.get(2) == null ? null : (Double) value.get(2);

      if (gpa != null) gpa = Math.floor(gpa) + 0.1;

      HCatRecord record = new DefaultHCatRecord(5);
      record.set(0, name);
      record.set(1, age);
      record.set(2, gpa);

      context.write(null, record);

    }
View Full Code Here

Examples of org.apache.hive.hcatalog.data.DefaultHCatRecord

      Iterator<IntWritable> iter = values.iterator();
      while (iter.hasNext()) {
        sum++;
        iter.next();
      }
      HCatRecord record = new DefaultHCatRecord(2);
      record.set(0, key.get());
      record.set(1, sum);

      context.write(null, record);
    }
View Full Code Here

Examples of org.apache.hive.hcatalog.data.DefaultHCatRecord

    int i = 0;
    for (HCatFieldSchema fSchema : computedSchema.getFields()) {
      outgoing.add(getJavaObj(tuple.get(i++), fSchema));
    }
    try {
      writer.write(null, new DefaultHCatRecord(outgoing));
    } catch (InterruptedException e) {
      throw new BackendException("Error while writing tuple: " + tuple, PigHCatUtil.PIG_EXCEPTION_CODE, e);
    }
  }
View Full Code Here

Examples of org.apache.hive.hcatalog.data.DefaultHCatRecord

      throws IOException, InterruptedException {
      String name = (String) value.get(0);
      int age = (Integer) value.get(1);
      String ds = (String) value.get(3);

      HCatRecord record = (filter == null ? new DefaultHCatRecord(3) : new DefaultHCatRecord(2));
      record.set(0, name);
      record.set(1, age);
      if (filter == null) record.set(2, ds);

      context.write(null, record);
View Full Code Here

Examples of org.apache.hive.hcatalog.data.DefaultHCatRecord

      throws IOException, InterruptedException {
      s = value.get(0) == null ? null : (String) value.get(0);
      i = value.get(1) == null ? null : (Integer) value.get(1);
      d = value.get(2) == null ? null : (Double) value.get(2);

      HCatRecord record = new DefaultHCatRecord(5);
      record.set(0, s);
      record.set(1, i);
      record.set(2, d);

      context.write(null, record);

    }
View Full Code Here

Examples of org.apache.hive.hcatalog.data.DefaultHCatRecord

      b = (Long) value.get(3);
      f = (Float) value.get(4);
      d = (Double) value.get(5);
      s = (String) value.get(6);

      HCatRecord record = new DefaultHCatRecord(7);
      record.set(0, t);
      record.set(1, si);
      record.set(2, i);
      record.set(3, b);
      record.set(4, f);
      record.set(5, d);
      record.set(6, s);

      context.write(null, record);

    }
View Full Code Here

Examples of org.apache.hive.hcatalog.data.DefaultHCatRecord

      throws IOException, InterruptedException {
      s = value.get(0) == null ? null : (String) value.get(0);
      i = value.get(1) == null ? null : (Integer) value.get(1);
      d = value.get(2) == null ? null : (Double) value.get(2);

      HCatRecord record = new DefaultHCatRecord(3);
      record.set(0, s);
      record.set(1, i);
      record.set(2, d);

      context.write(null, record);

    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.