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 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()); }
/** * 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()); } } }
/** * Adds the to indexed column list. * * @param indexInfo * the index info */ public void addToIndexedColumnList(IndexInfo indexInfo) { ColumnInfo columnInfo = new ColumnInfo(); columnInfo.setColumnName(indexInfo.getColumnName()); if (getEmbeddedColumnMetadatas().isEmpty() || !getEmbeddedColumnMetadatas().get(0).getColumns().contains(columnInfo)) { if (!columnToBeIndexed.contains(indexInfo)) { columnToBeIndexed.add(indexInfo); } } } }
/** * 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); }
columnDef.setIndex_type(CassandraIndexHelper.getIndexType(indexInfo.getIndexType()));
Assert.assertNotSame(embeddedColumnInfo, embedded2); IndexInfo indexInfo = new IndexInfo("personName"); indexInfo.setIndexType("KEYS"); indexInfo.setMaxValue(12); indexInfo.setMinValue(1);
/** * Gets the column to be indexed. * * @param columnName * the column name * @return the column to be indexed */ public IndexInfo getColumnToBeIndexed(String columnName) { IndexInfo idxInfo = new IndexInfo(columnName); if (columnToBeIndexed.contains(idxInfo)) { int index = columnToBeIndexed.indexOf(idxInfo); return getColumnsToBeIndexed().get(index); } return idxInfo; }
columnInfo.setColumnName(indexInfo.getColumnName()); if (!embeddedIndexes.contains(indexInfo.getColumnName())) indexInfo.getColumnName()); indexInfo.getColumnName(), tableInfo.getTableName(), ire); throw new SchemaGenerationException("Error occurred while creating indexes on column " + indexInfo.getColumnName() + " of table " + tableInfo.getTableName(), ire, "Cassandra", databaseName);
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); }
columnDef.setIndex_type(CassandraIndexHelper.getIndexType(indexInfo.getIndexType()));
/** * getJoinColumn method return ColumnInfo for the join column * * @param columnType * * @param String * joinColumnName. * @return ColumnInfo object columnInfo. */ private ColumnInfo getJoinColumn(TableInfo tableInfo, String joinColumnName, Class columnType) { ColumnInfo columnInfo = new ColumnInfo(); columnInfo.setColumnName(joinColumnName); columnInfo.setIndexable(true); IndexInfo indexInfo = new IndexInfo(joinColumnName); tableInfo.addToIndexedColumnList(indexInfo); columnInfo.setType(columnType); return columnInfo; }
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); }
@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()); }
if (views.get(indexInfo.getColumnName()) == null) logger.warn("No view exist for column " + indexInfo.getColumnName() + " of table " + tableInfo.getTableName() + "so any query on column " + indexInfo.getColumnName() + "will not produce any result");
/** * 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; }
/** * Add {@link DiscriminatorColumn} for schema generation. * * @param tableInfo * table info. * @param entityType * entity type. */ private void onInheritedProperty(TableInfo tableInfo, EntityType entityType) { String discrColumn = ((AbstractManagedType) entityType).getDiscriminatorColumn(); if (discrColumn != null) { ColumnInfo columnInfo = new ColumnInfo(); columnInfo.setColumnName(discrColumn); columnInfo.setType(String.class); columnInfo.setIndexable(true); IndexInfo idxInfo = new IndexInfo(discrColumn); tableInfo.addColumnInfo(columnInfo); tableInfo.addToIndexedColumnList(idxInfo); } }
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); }
createViewIfNotExist(views, indexInfo.getColumnName());
/** * * @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); }