Package org.hivedb.meta

Examples of org.hivedb.meta.SecondaryIndex


  class SecondaryIndexRowMapper implements RowMapper {
    public Object mapRow(ResultSet rs, int index) throws SQLException{
      int jdbcType = Types.OTHER;
      jdbcType = JdbcTypeMapper.parseJdbcType(rs.getString("db_type"));
     
      SecondaryIndex si = new SecondaryIndex(rs.getInt("id"),
          rs.getString("column_name"), jdbcType);
      return si;
    }
View Full Code Here


    resource.setPartitionDimension(createEmptyPartitionDimension());
    return resource;
  }

  protected SecondaryIndex createSecondaryIndex() {
    SecondaryIndex index = new SecondaryIndex("FOO", java.sql.Types.VARCHAR);
    index.setResource(createResource());
    return index;
  }
View Full Code Here

    index.setResource(createResource());
    return index;
  }

  protected SecondaryIndex createSecondaryIndex(int id) {
    SecondaryIndex index = new SecondaryIndex(id, "FOO", java.sql.Types.VARCHAR);
    index.setResource(createResource());
    return index;
  }
View Full Code Here

    Collection<SecondaryIndex> secondaryIndexes = new ArrayList<SecondaryIndex>();
    if (indexes != null) {
      for (Map<String, String> index : indexes) {
        String name = index.get("name");
        String type = index.get("type");
        SecondaryIndex secondaryIndex = new SecondaryIndex(name, JdbcTypeMapper.parseJdbcType(stringToVarchar(type)));
        secondaryIndexes.add(secondaryIndex);
      }
    }
    return secondaryIndexes;
  }
View Full Code Here

      throw new HiveRuntimeException(e.getMessage(), e);
    }
  }

  private SecondaryIndex createSecondaryIndex(EntityIndexConfig config) {
    return new SecondaryIndex(config.getIndexName(), JdbcTypeMapper.primitiveTypeToJdbcType(config.getIndexClass()));
  }
View Full Code Here

    return new HiveDiff(missingResources, indexMap);
  }
  private Unary<EntityIndexConfig, SecondaryIndex> configToIndex() {
    return new Unary<EntityIndexConfig, SecondaryIndex>(){
      public SecondaryIndex f(EntityIndexConfig item) {
        return new SecondaryIndex(item.getIndexName(), JdbcTypeMapper.primitiveTypeToJdbcType(item.getIndexClass()));
      }};
  }
View Full Code Here

  private SecondaryIndex getSecondaryIndex(String resourceName, String secondaryIndexName) {
    return getResource(resourceName).getSecondaryIndex(secondaryIndexName);
  }

  public void deleteSecondaryIndexKey(String resource, String secondaryIndex, Object secondaryIndexKey, Object resourceId) throws HiveLockableException {
    SecondaryIndex index = getSecondaryIndex(resource, secondaryIndex);
    Preconditions.isWritable(directory.getKeySemaphoresOfResourceId(getResource(resource), resourceId), semaphore);
    if (!directory.doesSecondaryIndexKeyExist(index, secondaryIndexKey, resourceId))
      throw new HiveKeyNotFoundException(
          String.format(
              "Secondary index key %s of secondary index %s does not exist",
              secondaryIndexKey, index.getName()), secondaryIndexKey);

    directory.deleteSecondaryIndexKey(index, secondaryIndexKey, resourceId);
  }
View Full Code Here

    // Add it to the Hive
    product = hive.addResource(product);

    //Now create a SecondaryIndex
    SecondaryIndex nameIndex = new SecondaryIndex("name", Types.VARCHAR);
    //Add it to the Hive
    nameIndex = hive.addSecondaryIndex(product, nameIndex);
    //Note: SecondaryIndexes are identified by ResourceName.IndexColumnName

    //Now lets add a product to the hive.
    Product spork = new Product(23, "Spork", "Cutlery");
    //First we have to add a primary index entry in order to get allocated to a data node.
    //While it is possible to write a record to multiple locations within the Hive, the default implementation
    //inserts a single copy.
    hive.directory().insertPrimaryIndexKey(spork.getType());
    //Next we insert the record into the assigned data node
    Collection<SimpleJdbcDaoSupport> sporkDaos = hive.connection().daoSupport().get(spork.getType(), AccessType.ReadWrite);
    PreparedStatementCreatorFactory stmtFactory =
      new PreparedStatementCreatorFactory(productInsertSql, new int[]{Types.INTEGER, Types.VARCHAR, Types.VARCHAR});
    Object[] parameters = new Object[]{spork.getId(), spork.getName(), spork.getType()};
    for (JdbcDaoSupport dao : sporkDaos)
      dao.getJdbcTemplate().update(stmtFactory.newPreparedStatementCreator(parameters));

    //Update the resource id so that the hive can locate it
    hive.directory().insertResourceId(resourceName, spork.getId(), spork.getType());
    //Finally we update the SecondaryIndex
    hive.directory().insertSecondaryIndexKey(resourceName, "name", spork.getName(), spork.getId());

    //Retrieve spork by Primary Key
    sporkDaos = hive.connection().daoSupport().get(spork.getType(), AccessType.ReadWrite);
    parameters = new Object[]{spork.getId()};

    //Here I am taking advantage of the fact that I know there is only one copy.
    Product productA = (Product) Atom.getFirst(sporkDaos).getJdbcTemplate().queryForObject(selectProductById, parameters, new ProductRowMapper());
    //Make sure its a spork
    Assert.assertEquals(spork.getName(), productA.getName());

    //Retrieve the spork by Name
    sporkDaos = (Collection<SimpleJdbcDaoSupport>) hive.connection().daoSupport().get(resourceName, nameIndex.getName(), spork.getName(), AccessType.Read);
    parameters = new Object[]{spork.getName()};
    Product productB = (Product) Atom.getFirst(sporkDaos).getJdbcTemplate().queryForObject(selectProductByName, parameters, new ProductRowMapper());
    //Make sure its a spork
    Assert.assertEquals(spork.getId(), productB.getId());
View Full Code Here

  public void testDelete() throws Exception {
    SecondaryIndexDao d = new SecondaryIndexDao(getDataSource(getConnectString(getHiveDatabaseName())));
    int initialSize = d.loadAll().size();
    int id = d.create(createSecondaryIndex());
    assertEquals(initialSize+1,d.loadAll().size());
    SecondaryIndex s = createSecondaryIndex(id);
    s.setResource(createResource());
    d.delete(s);
    assertEquals(initialSize,d.loadAll().size());
  }
View Full Code Here

    return resource;
  }

  private Collection<SecondaryIndex> createSecondaryIndexes() {
    return Arrays.asList(
      new SecondaryIndex("name", Types.VARCHAR),
      new SecondaryIndex("num", Types.INTEGER));
  }
View Full Code Here

TOP

Related Classes of org.hivedb.meta.SecondaryIndex

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.