/** * isInedexesPresent method return whether indexes present or not on * particular column. * * @param columnInfo * the column info * @param columnDef * the column def * @param isCql3Enabled * the is cql3 enabled * @return true, if is indexes present * @throws Exception * the exception */ private boolean isColumnPresent(ColumnInfo columnInfo, ColumnDef columnDef, boolean isCql3Enabled) throws Exception { return (new String(columnDef.getName(), Constants.ENCODING).equals(columnInfo.getColumnName())); }
/** * Creates the index using thrift. * * @param tableInfo * the table info * @param cfDef * the cf def * @throws Exception * the exception */ private void createIndexUsingThrift(TableInfo tableInfo, CfDef cfDef) throws Exception { for (IndexInfo indexInfo : tableInfo.getColumnsToBeIndexed()) { for (ColumnDef columnDef : cfDef.getColumn_metadata()) { if (new String(columnDef.getName(), Constants.ENCODING).equals(indexInfo.getColumnName())) { columnDef.setIndex_type(CassandraIndexHelper.getIndexType(indexInfo.getIndexType())); // columnDef.setIndex_name(indexInfo.getIndexName()); } } } cassandra_client.system_update_column_family(cfDef); }
for (ColumnDef columnDef : cfDef.getColumn_metadata()) if (new String(columnDef.getName(), Constants.ENCODING).equals("AGE")) Assert.assertTrue(columns.contains(new String(columnDef.getName(), Constants.ENCODING))); Assert.assertEquals(IndexType.KEYS, columnDef.index_type); Assert.assertTrue(columns.contains(new String(columnDef.getName(), Constants.ENCODING))); Assert.assertEquals(IndexType.KEYS, columnDef.index_type);
if (new String(columnDef.getName(), Constants.ENCODING).equals("AGE")) Assert.assertTrue(columns.contains(new String(columnDef.getName(), Constants.ENCODING))); Assert.assertEquals(IndexType.KEYS, columnDef.index_type); Assert.assertTrue(columns.contains(new String(columnDef.getName(), Constants.ENCODING))); Assert.assertEquals(IndexType.KEYS, columnDef.index_type);
Assert.assertTrue(columns.contains(new String(columnDef.getName(), Constants.ENCODING))); Assert.assertNull(columnDef.index_name);
for (ColumnDef columnDef : cfDef.getColumn_metadata()) if (new String(columnDef.getName(), Constants.ENCODING).equals("AGE")) Assert.assertEquals("PERSON_NAME", new String(columnDef.getName(), Constants.ENCODING)); Assert.assertNotNull(columnDef.index_name); Assert.assertEquals(UTF8Type.class.getName(), columnDef.getValidation_class());
for (ColumnDef columnDef : cfDef.getColumn_metadata()) if (new String(columnDef.getName(), Constants.ENCODING).equals("AGE")) Assert.assertEquals("PERSON_NAME", new String(columnDef.getName(), Constants.ENCODING)); Assert.assertNotNull(columnDef.index_name); Assert.assertEquals(UTF8Type.class.getName(), columnDef.getValidation_class());
Assert.assertTrue(columns.contains(new String(columnDef.getName(), Constants.ENCODING))); Assert.assertNotNull(columnDef.index_name);
indexList.add(new StringAccessor().fromBytes(String.class, columnDef.getName()));
@Override public ByteBuffer getRawName() { return ByteBuffer.wrap(this.columnDef.getName()); }
@Override public ByteBuffer getRawName() { return ByteBuffer.wrap(this.columnDef.getName()); }
/** return partition keys */ public String[] getPartitionKeys(String location, Job job) throws IOException { if (!usePartitionFilter) return null; List<ColumnDef> indexes = getIndexes(); String[] partitionKeys = new String[indexes.size()]; for (int i = 0; i < indexes.size(); i++) { partitionKeys[i] = new String(indexes.get(i).getName()); } return partitionKeys; }
/** * isInedexesPresent method return whether indexes present or not on * particular column. * * @param columnInfo * the column info * @param cfDef * the cf def * @return true, if is indexes present * @throws UnsupportedEncodingException */ private boolean isColumnPresent(ColumnInfo columnInfo, ColumnDef columnDef, boolean isCql3Enabled) throws Exception { return (new String(columnDef.getName(), Constants.ENCODING).equals(columnInfo.getColumnName())); }
/** * Get specific ColumnDef in column family meta data by column name * @param columnFamily - CfDef record * @param columnName - column name represented as byte[] * @return ColumnDef - found column definition */ private ColumnDef getColumnDefByName(CfDef columnFamily, ByteBuffer columnName) { for (ColumnDef columnDef : columnFamily.getColumn_metadata()) { byte[] currName = columnDef.getName(); if (ByteBufferUtil.compare(currName, columnName) == 0) { return columnDef; } } return null; }
public Object getFieldValue(_Fields field) { switch (field) { case NAME: return getName(); case VALIDATION_CLASS: return getValidation_class(); case INDEX_TYPE: return getIndex_type(); case INDEX_NAME: return getIndex_name(); case INDEX_OPTIONS: return getIndex_options(); } throw new IllegalStateException(); }
/** * Get validator for specific column value * @param cfDef - CfDef object representing column family with metadata * @param columnNameInBytes - column name as byte array * @return AbstractType - validator for column value */ private AbstractType<?> getValidatorForValue(CfDef cfDef, byte[] columnNameInBytes) { String defaultValidator = cfDef.default_validation_class; for (ColumnDef columnDefinition : cfDef.getColumn_metadata()) { byte[] nameInBytes = columnDefinition.getName(); if (Arrays.equals(nameInBytes, columnNameInBytes)) { return getFormatType(columnDefinition.getValidation_class()); } } if (defaultValidator != null && !defaultValidator.isEmpty()) { return getFormatType(defaultValidator); } return null; }
public Object getFieldValue(_Fields field) { switch (field) { case NAME: return getName(); case VALIDATION_CLASS: return getValidation_class(); case INDEX_TYPE: return getIndex_type(); case INDEX_NAME: return getIndex_name(); case INDEX_OPTIONS: return getIndex_options(); } throw new IllegalStateException(); }
public Object getFieldValue(_Fields field) { switch (field) { case NAME: return getName(); case VALIDATION_CLASS: return getValidation_class(); case INDEX_TYPE: return getIndex_type(); case INDEX_NAME: return getIndex_name(); case INDEX_OPTIONS: return getIndex_options(); } throw new IllegalStateException(); }
/** schema: (value, value, value) where keys are in the front. */ public ResourceSchema getSchema(String location, Job job) throws IOException { setLocation(location, job); CfInfo cfInfo = getCfInfo(loadSignature); CfDef cfDef = cfInfo.cfDef; // top-level schema, no type ResourceSchema schema = new ResourceSchema(); // get default marshallers and validators Map<MarshallerType, AbstractType> marshallers = getDefaultMarshallers(cfDef); Map<ByteBuffer, AbstractType> validators = getValidatorMap(cfDef); // will contain all fields for this schema List<ResourceFieldSchema> allSchemaFields = new ArrayList<ResourceFieldSchema>(); for (ColumnDef cdef : cfDef.column_metadata) { ResourceFieldSchema valSchema = new ResourceFieldSchema(); AbstractType validator = validators.get(cdef.name); if (validator == null) validator = marshallers.get(MarshallerType.DEFAULT_VALIDATOR); valSchema.setName(new String(cdef.getName())); valSchema.setType(getPigType(validator)); allSchemaFields.add(valSchema); } // top level schema contains everything schema.setFields(allSchemaFields.toArray(new ResourceFieldSchema[allSchemaFields.size()])); return schema; }
private void createIndexUsingThrift(TableInfo tableInfo, CfDef cfDef) throws Exception { for (IndexInfo indexInfo : tableInfo.getColumnsToBeIndexed()) { for (ColumnDef columnDef : cfDef.getColumn_metadata()) { if (new String(columnDef.getName(), Constants.ENCODING).equals(indexInfo.getColumnName())) { columnDef.setIndex_type(CassandraIndexHelper.getIndexType(indexInfo.getIndexType())); } } } cassandra_client.system_update_column_family(cfDef); }