private void indexColumn(IndexInfo indexInfo, DBCollection collection) { DBObject keys = new BasicDBObject(); getIndexType(indexInfo.getIndexType(), keys, indexInfo.getColumnName()); DBObject options = new BasicDBObject(); if (indexInfo.getMinValue() != null) { options.put(MongoDBConstants.MIN, indexInfo.getMinValue()); } if (indexInfo.getMaxValue() != null) { options.put(MongoDBConstants.MAX, indexInfo.getMaxValue()); } if (indexInfo.getIndexType() != null && (indexInfo.getIndexType().toLowerCase()).equals("unique")) { options.put("unique", true); } collection.createIndex(keys, options); KunderaCoreUtils.printQuery("Create indexes on:" + keys, showQuery); }
/** * Creates the index on table. * * @param tableInfo * the table info */ private void createIndexOnTable(TableInfo tableInfo) { List<IndexInfo> indexColumns = tableInfo.getColumnsToBeIndexed(); for (IndexInfo indexInfo : indexColumns) { if (indexInfo.getIndexType() != null && indexInfo.getIndexType().toLowerCase().equals(Constants.COMPOSITE)) { String[] columnNames = indexInfo.getColumnName().split(Constants.COMMA); createIndex(tableInfo.getTableName(), indexInfo.getIndexName(), columnNames); } else { createIndex(tableInfo.getTableName(), indexInfo.getIndexName(), indexInfo.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); }
private void indexEmbeddedColumn(IndexInfo indexInfo, String embeddedColumnName, DBCollection collection) { DBObject keys = new BasicDBObject(); getIndexType(indexInfo.getIndexType(), keys, embeddedColumnName + "." + indexInfo.getColumnName()); DBObject options = new BasicDBObject(); if (indexInfo.getMinValue() != null) { options.put(MongoDBConstants.MIN, indexInfo.getMinValue()); } if (indexInfo.getMaxValue() != null) { options.put(MongoDBConstants.MAX, indexInfo.getMaxValue()); } collection.createIndex(keys, options); KunderaCoreUtils.printQuery("Create indexes on:" + keys, showQuery); }
@Test public void testWithSingleValueConstructor() { IndexInfo indexInfo = new IndexInfo("personName"); indexInfo.setIndexType("KEYS"); indexInfo.setMaxValue(12); indexInfo.setMinValue(1); Assert.assertEquals(1, indexInfo.getMinValue().intValue()); Assert.assertEquals(1, indexInfo.getMinValue().intValue()); Assert.assertEquals("KEYS", indexInfo.getIndexType()); Assert.assertEquals("personName", indexInfo.getColumnName()); }
columnDef.setIndex_type(CassandraIndexHelper.getIndexType(indexInfo.getIndexType()));
@Test public void testWithMultiValueConstructor() { IndexInfo indexInfo = new IndexInfo("personName",12,1,"KEYS", "personName"); indexInfo.setIndexType("KEYS"); indexInfo.setMaxValue(12); indexInfo.setMinValue(1); Assert.assertEquals(12, indexInfo.getMaxValue().intValue()); Assert.assertEquals(1, indexInfo.getMinValue().intValue()); Assert.assertEquals("KEYS", indexInfo.getIndexType()); Assert.assertEquals("personName", indexInfo.getColumnName()); }
columnDef.setIndex_type(CassandraIndexHelper.getIndexType(indexInfo.getIndexType()));
/** * getColumnMetadata use for getting column metadata for specific * columnInfo. * * @param columnInfo * the column info * @param tableInfo * the table info * @return the column metadata */ private ColumnDef getColumnMetadata(ColumnInfo columnInfo, TableInfo tableInfo) { ColumnDef columnDef = new ColumnDef(); columnDef.setName(columnInfo.getColumnName().getBytes()); columnDef.setValidation_class(CassandraValidationClassMapper.getValidationClass(columnInfo.getType(), isCql3Enabled(tableInfo))); if (columnInfo.isIndexable()) { IndexInfo indexInfo = tableInfo.getColumnToBeIndexed(columnInfo.getColumnName()); columnDef.setIndex_type(CassandraIndexHelper.getIndexType(indexInfo.getIndexType())); // if (!indexInfo.getIndexName().equals(indexInfo.getColumnName())) // { // columnDef.setIndex_name(indexInfo.getIndexName()); // } } return columnDef; }
private void indexColumn(IndexInfo indexInfo, DBCollection collection) { DBObject keys = new BasicDBObject(); getIndexType(indexInfo.getIndexType(), keys, indexInfo.getColumnName()); DBObject options = new BasicDBObject(); if (indexInfo.getMinValue() != null) { options.put(MongoDBConstants.MIN, indexInfo.getMinValue()); } if (indexInfo.getMaxValue() != null) { options.put(MongoDBConstants.MAX, indexInfo.getMaxValue()); } if (indexInfo.getIndexType() != null && (indexInfo.getIndexType().toLowerCase()).equals("unique")) { options.put("unique", true); } collection.createIndex(keys, options); KunderaCoreUtils.printQuery("Create indexes on:" + keys, showQuery); }
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); }
private void indexEmbeddedColumn(IndexInfo indexInfo, String embeddedColumnName, DBCollection collection) { DBObject keys = new BasicDBObject(); getIndexType(indexInfo.getIndexType(), keys, embeddedColumnName + "." + indexInfo.getColumnName()); DBObject options = new BasicDBObject(); if (indexInfo.getMinValue() != null) { options.put(MongoDBConstants.MIN, indexInfo.getMinValue()); } if (indexInfo.getMaxValue() != null) { options.put(MongoDBConstants.MAX, indexInfo.getMaxValue()); } collection.createIndex(keys, options); KunderaCoreUtils.printQuery("Create indexes on:" + keys, showQuery); }
/** * * @param tableInfo * @param cfDef */ private void getCounterColumnFamilyMetadata(TableInfo tableInfo, CfDef cfDef) { cfDef.setDefault_validation_class(CounterColumnType.class.getSimpleName()); List<ColumnDef> counterColumnDefs = new ArrayList<ColumnDef>(); List<ColumnInfo> columnInfos = tableInfo.getColumnMetadatas(); if (columnInfos != null) { for (ColumnInfo columnInfo : columnInfos) { ColumnDef columnDef = new ColumnDef(); if (columnInfo.isIndexable()) { IndexInfo indexInfo = tableInfo.getColumnToBeIndexed(columnInfo.getColumnName()); columnDef.setIndex_type(CassandraIndexHelper.getIndexType(indexInfo.getIndexType())); } columnDef.setName(columnInfo.getColumnName().getBytes()); columnDef.setValidation_class(CounterColumnType.class.getName()); counterColumnDefs.add(columnDef); } } cfDef.setColumn_metadata(counterColumnDefs); }
columnDef.setIndex_type(CassandraIndexHelper.getIndexType(indexInfo.getIndexType()));
/** * getColumnMetadata use for getting column metadata for specific * columnInfo. * * @param columnInfo * the column info * @return the column metadata */ private ColumnDef getColumnMetadata(ColumnInfo columnInfo, TableInfo tableInfo) { ColumnDef columnDef = new ColumnDef(); columnDef.setName(columnInfo.getColumnName().getBytes()); columnDef.setValidation_class(CassandraValidationClassMapper.getValidationClass(columnInfo.getType(), isCql3Enabled(tableInfo))); if (columnInfo.isIndexable()) { IndexInfo indexInfo = tableInfo.getColumnToBeIndexed(columnInfo.getColumnName()); columnDef.setIndex_type(CassandraIndexHelper.getIndexType(indexInfo.getIndexType())); } return columnDef; }