Package org.apache.hcatalog.data.schema

Examples of org.apache.hcatalog.data.schema.HCatFieldSchema


    public static void createTable(String metaStoreUrl, String databaseName, String tableName,
                                   List<String> partitionKeys) throws Exception {
        HCatClient client = HiveCatalogService.get(metaStoreUrl);
        ArrayList<HCatFieldSchema> cols = new ArrayList<HCatFieldSchema>();
        cols.add(new HCatFieldSchema("id", HCatFieldSchema.Type.INT, "id comment"));
        cols.add(new HCatFieldSchema("value", HCatFieldSchema.Type.STRING, "value comment"));

        List<HCatFieldSchema> partitionSchema = new ArrayList<HCatFieldSchema>();
        for (String partitionKey : partitionKeys) {
            partitionSchema.add(new HCatFieldSchema(partitionKey, HCatFieldSchema.Type.STRING, ""));
        }

        HCatCreateTableDesc tableDesc = HCatCreateTableDesc
                .create(databaseName, tableName, cols)
                .ifNotExists(true)
View Full Code Here


    }

    public static void createExternalTable(String metaStoreUrl, String databaseName, String tableName,
                                           List<String> partitionKeys, String externalLocation) throws Exception {
        ArrayList<HCatFieldSchema> cols = new ArrayList<HCatFieldSchema>();
        cols.add(new HCatFieldSchema("id", HCatFieldSchema.Type.INT, "id comment"));
        cols.add(new HCatFieldSchema("value", HCatFieldSchema.Type.STRING, "value comment"));

        List<HCatFieldSchema> partitionSchema = new ArrayList<HCatFieldSchema>();
        for (String partitionKey : partitionKeys) {
            partitionSchema.add(new HCatFieldSchema(partitionKey, HCatFieldSchema.Type.STRING, ""));
        }

        HCatCreateTableDesc tableDesc = HCatCreateTableDesc
                .create(databaseName, tableName, cols)
                .fileFormat("rcfile")
View Full Code Here

        client.createDatabase(dbDesc);
    }

    public void createTable() throws Exception {
        ArrayList<HCatFieldSchema> cols = new ArrayList<HCatFieldSchema>();
        cols.add(new HCatFieldSchema("id", HCatFieldSchema.Type.INT, "id comment"));
        cols.add(new HCatFieldSchema("value", HCatFieldSchema.Type.STRING, "value comment"));

        List<HCatFieldSchema> partitionSchema = Arrays.asList(
                new HCatFieldSchema("ds", HCatFieldSchema.Type.STRING, ""),
                new HCatFieldSchema("region", HCatFieldSchema.Type.STRING, "")
        );

        HCatCreateTableDesc tableDesc = HCatCreateTableDesc
                .create(DATABASE_NAME, TABLE_NAME, cols)
                .fileFormat("rcfile")
View Full Code Here

        client.createTable(tableDesc);
    }

    public void createExternalTable() throws Exception {
        ArrayList<HCatFieldSchema> cols = new ArrayList<HCatFieldSchema>();
        cols.add(new HCatFieldSchema("id", HCatFieldSchema.Type.INT, "id comment"));
        cols.add(new HCatFieldSchema("value", HCatFieldSchema.Type.STRING, "value comment"));

        List<HCatFieldSchema> partitionSchema = Arrays.asList(
                new HCatFieldSchema("ds", HCatFieldSchema.Type.STRING, ""),
                new HCatFieldSchema("region", HCatFieldSchema.Type.STRING, "")
        );

        HCatCreateTableDesc tableDesc = HCatCreateTableDesc
                .create(DATABASE_NAME, EXTERNAL_TABLE_NAME, cols)
                .fileFormat("rcfile")
View Full Code Here

      if (fs.exists(inputLocation)) {
        fs.delete(inputLocation, true);
      }

      List<HCatFieldSchema> partKeys = new ArrayList<HCatFieldSchema>(2);
      partKeys.add(new HCatFieldSchema("emp_country", HCatFieldSchema.Type.STRING, ""));
      partKeys.add(new HCatFieldSchema("emp_state", HCatFieldSchema.Type.STRING, ""));
      partSchema = new HCatSchema(partKeys);

      runPartExport("237,Krishna,01/01/1990,M,IN,TN", "in", "tn");
      setUp();
      runPartExport("238,Kalpana,01/01/2000,F,IN,KA\n", "in", "ka");
View Full Code Here

      if (fs.exists(inputLocation)) {
        fs.delete(inputLocation, true);
      }

      List<HCatFieldSchema> partKeys = new ArrayList<HCatFieldSchema>(2);
      partKeys.add(new HCatFieldSchema("emp_country", HCatFieldSchema.Type.STRING, ""));
      partKeys.add(new HCatFieldSchema("emp_state", HCatFieldSchema.Type.STRING, ""));
      partSchema = new HCatSchema(partKeys);

      runPartExport("237,Krishna,01/01/1990,M,IN,TN", "in", "tn");
      setUp();
      runPartExport("238,Kalpana,01/01/2000,F,IN,KA\n", "in", "ka");
View Full Code Here

      if (fs.exists(inputLocation)) {
        fs.delete(inputLocation, true);
      }

      List<HCatFieldSchema> partKeys = new ArrayList<HCatFieldSchema>(2);
      partKeys.add(new HCatFieldSchema("emp_country", HCatFieldSchema.Type.STRING, ""));
      partKeys.add(new HCatFieldSchema("emp_state", HCatFieldSchema.Type.STRING, ""));
      partSchema = new HCatSchema(partKeys);

      runPartExport("237,Krishna,01/01/1990,M,IN,TN", "in", "tn");
      setUp();
      runPartExport("238,Kalpana,01/01/2000,F,IN,KA\n", "in", "ka");
View Full Code Here

import java.util.List;

public class TestHCatSchema extends TestCase {
  public void testCannotAddFieldMoreThanOnce() throws HCatException {
    List<HCatFieldSchema> fieldSchemaList = new ArrayList<HCatFieldSchema>();
    fieldSchemaList.add(new HCatFieldSchema("name", HCatFieldSchema.Type.STRING, "What's your handle?"));
    fieldSchemaList.add(new HCatFieldSchema("age", HCatFieldSchema.Type.INT, "So very old"));

    HCatSchema schema = new HCatSchema(fieldSchemaList);

    assertTrue(schema.getFieldNames().contains("age"));
    assertEquals(2, schema.getFields().size());

    try {
      schema.append(new HCatFieldSchema("age", HCatFieldSchema.Type.INT, "So very old"));
      fail("Was able to append field schema with same name");
    } catch(HCatException he) {
      assertTrue(he.getMessage().contains("Attempt to append HCatFieldSchema with already existing name: age."));
    }

    assertTrue(schema.getFieldNames().contains("age"));
    assertEquals(2, schema.getFields().size());

    // Should also not be able to add fields of different types with same name
    try {
      schema.append(new HCatFieldSchema("age", HCatFieldSchema.Type.STRING, "Maybe spelled out?"));
      fail("Was able to append field schema with same name");
    } catch(HCatException he) {
      assertTrue(he.getMessage().contains("Attempt to append HCatFieldSchema with already existing name: age."));
    }
View Full Code Here

  }

  public void testCannotInstantiateSchemaWithRepeatedFieldNames() throws HCatException {
      List<HCatFieldSchema> fieldSchemaList = new ArrayList<HCatFieldSchema>();

      fieldSchemaList.add(new HCatFieldSchema("memberID", HCatFieldSchema.Type.INT, "as a number"));
      fieldSchemaList.add(new HCatFieldSchema("location", HCatFieldSchema.Type.STRING, "there's Waldo"));

      // No duplicate names.  This should be ok
      HCatSchema schema = new HCatSchema(fieldSchemaList);

      fieldSchemaList.add(new HCatFieldSchema("memberID", HCatFieldSchema.Type.STRING, "as a String"));

      // Now a duplicated field name.  Should fail
      try {
        HCatSchema schema2 = new HCatSchema(fieldSchemaList);
        fail("Able to add duplicate field name");
View Full Code Here

      }

      List<HCatFieldSchema> hcatFields = new ArrayList<HCatFieldSchema>();
      List<String> partVals = new ArrayList<String>();
      for (String key : partitions.keySet()) {
        hcatFields.add(new HCatFieldSchema(key, HCatFieldSchema.Type.STRING, ""));
        partVals.add(partitions.get(key));
      }

      HCatSchema outputSchema = convertPigSchemaToHCatSchema(pigSchema,
          hcatTblSchema);
View Full Code Here

TOP

Related Classes of org.apache.hcatalog.data.schema.HCatFieldSchema

Copyright © 2018 www.massapicom. 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.