List of usage examples for org.apache.cassandra.exceptions InvalidRequestException InvalidRequestException
public InvalidRequestException(String msg)
From source file:com.stratio.cassandra.index.RowIndexSearcher.java
License:Apache License
/** * {@inheritDoc}//from w w w.j a v a 2 s .c o m */ @Override public void validate(IndexExpression indexExpression) throws InvalidRequestException { try { String json = UTF8Type.instance.compose(indexExpression.value); Search.fromJson(json).validate(schema); } catch (Exception e) { throw new InvalidRequestException(e.getMessage()); } }
From source file:com.stratio.cassandra.lucene.IndexQueryHandler.java
License:Apache License
@Override /** {@inheritDoc} */ public ResultMessage process(String query, QueryState state, QueryOptions options, Map<String, ByteBuffer> customPayload) { ParsedStatement.Prepared p = QueryProcessor.getStatement(query, state.getClientState()); options.prepare(p.boundNames);//from www .jav a2s.co m CQLStatement prepared = p.statement; if (prepared.getBoundTerms() != options.getValues().size()) { throw new InvalidRequestException("Invalid amount of bind variables"); } if (!state.getClientState().isInternal) { QueryProcessor.metrics.regularStatementsExecuted.inc(); } return processStatement(prepared, state, options); }
From source file:com.stratio.cassandra.lucene.IndexQueryHandler.java
License:Apache License
private ResultMessage process(SelectStatement select, QueryState state, QueryOptions options, RowFilter.CustomExpression expression) throws ReflectiveOperationException { // Validate expression ColumnFamilyStore cfs = Keyspace.open(select.keyspace()).getColumnFamilyStore(select.columnFamily()); Index index = (Index) cfs.indexManager.getIndex(expression.getTargetIndex()); Search search = index.validate(expression); // Check paging int limit = select.getLimit(options); int page = getPageSize(select, options); if (search.isTopK()) { if (limit == Integer.MAX_VALUE) { // Avoid unlimited throw new InvalidRequestException( "Top-k searches don't support paging, so a cautious LIMIT clause should be provided " + "to prevent excessive memory consumption."); } else if (page < limit) { String json = UTF8Type.instance.compose(expression.getValue()); logger.warn("Disabling paging of {} rows per page for top-k search requesting {} rows: {}", page, limit, json);/*from w w w . j av a2 s .com*/ return executeWithoutPaging(select, state, options); } } // Process return execute(select, state, options); }
From source file:com.stratio.cassandra.lucene.IndexSearcher.java
License:Apache License
/** * {@inheritDoc}/*w w w.j a va 2 s . co m*/ */ @Override public void validate(IndexExpression indexExpression) throws InvalidRequestException { try { String json = UTF8Type.instance.compose(indexExpression.value); SearchBuilder.fromJson(json).build().validate(schema); } catch (Exception e) { throw new InvalidRequestException(e.getMessage()); } }
From source file:org.elassandra.cluster.InternalCassandraClusterService.java
License:Apache License
public String buildUDT(final String ksName, final String cfName, final String name, final ObjectMapper objectMapper) throws RequestExecutionException { String typeName = cfName + "_" + objectMapper.fullPath().replace('.', '_'); if (!objectMapper.iterator().hasNext()) { throw new InvalidRequestException("Cannot create an empty nested type (not supported)"); }//www. j a v a2s . com // create sub-type first for (Iterator<Mapper> it = objectMapper.iterator(); it.hasNext();) { Mapper mapper = it.next(); if (mapper instanceof ObjectMapper) { buildCql(ksName, cfName, mapper.simpleName(), (ObjectMapper) mapper); } else if (mapper instanceof GeoPointFieldMapper) { buildGeoPointType(ksName); } } Pair<List<String>, List<String>> udt = getUDTInfo(ksName, typeName); if (udt == null) { // create new UDT. StringBuilder create = new StringBuilder( String.format((Locale) null, "CREATE TYPE IF NOT EXISTS \"%s\".\"%s\" ( ", ksName, typeName)); boolean first = true; for (Iterator<Mapper> it = objectMapper.iterator(); it.hasNext();) { Mapper mapper = it.next(); if (first) first = false; else create.append(", "); // Use only the last part of the fullname to build UDT. int lastDotIndex = mapper.name().lastIndexOf('.'); String shortName = (lastDotIndex > 0) ? mapper.name().substring(lastDotIndex + 1) : mapper.name(); if (isReservedKeyword(shortName)) throw new ConfigurationException(shortName + " is a reserved keyword"); create.append('\"').append(shortName).append("\" "); if (mapper instanceof ObjectMapper) { if (!mapper.cqlCollection().equals(CqlCollection.SINGLETON)) create.append(mapper.cqlCollectionTag()).append("<"); create.append("frozen<").append(cfName).append('_') .append(((ObjectMapper) mapper).fullPath().replace('.', '_')).append(">"); if (!mapper.cqlCollection().equals(CqlCollection.SINGLETON)) create.append(">"); } else if (mapper instanceof BaseGeoPointFieldMapper) { if (!mapper.cqlCollection().equals(CqlCollection.SINGLETON)) create.append(mapper.cqlCollectionTag()).append("<"); create.append("frozen<").append(GEO_POINT_TYPE).append(">"); if (!mapper.cqlCollection().equals(CqlCollection.SINGLETON)) create.append(">"); } else if (mapper instanceof GeoShapeFieldMapper) { if (!mapper.cqlCollection().equals(CqlCollection.SINGLETON)) create.append(mapper.cqlCollectionTag()).append("<"); create.append("frozen<").append("text").append(">"); if (!mapper.cqlCollection().equals(CqlCollection.SINGLETON)) create.append(">"); } else { String cqlType = mapperToCql.get(mapper.getClass()); if (mapper.cqlCollection().equals(CqlCollection.SINGLETON)) { create.append(cqlType); } else { create.append(mapper.cqlCollectionTag()).append("<"); if (!isNativeCql3Type(cqlType)) create.append("frozen<"); create.append(cqlType); if (!isNativeCql3Type(cqlType)) create.append(">"); create.append(">"); } } } create.append(" )"); if (logger.isDebugEnabled()) logger.debug("create UDT:" + create.toString()); QueryProcessor.process(create.toString(), ConsistencyLevel.LOCAL_ONE); } else { // update existing UDT for (Iterator<Mapper> it = objectMapper.iterator(); it.hasNext();) { Mapper mapper = it.next(); int lastDotIndex = mapper.name().lastIndexOf('.'); String shortName = (lastDotIndex > 0) ? mapper.name().substring(lastDotIndex + 1) : mapper.name(); if (isReservedKeyword(shortName)) throw new ConfigurationException(shortName + " is a reserved keyword"); StringBuilder update = new StringBuilder(String.format((Locale) null, "ALTER TYPE \"%s\".\"%s\" ADD \"%s\" ", ksName, typeName, shortName)); if (!udt.left.contains(shortName)) { if (mapper instanceof ObjectMapper) { if (!mapper.cqlCollection().equals(CqlCollection.SINGLETON)) update.append(mapper.cqlCollectionTag()).append("<"); update.append("frozen<").append(cfName).append('_') .append(((ObjectMapper) mapper).fullPath().replace('.', '_')).append(">"); if (!mapper.cqlCollection().equals(CqlCollection.SINGLETON)) update.append(">"); } else if (mapper instanceof GeoPointFieldMapper) { if (!mapper.cqlCollection().equals(CqlCollection.SINGLETON)) update.append(mapper.cqlCollectionTag()).append("<"); update.append("frozen<").append(GEO_POINT_TYPE).append(">"); if (!mapper.cqlCollection().equals(CqlCollection.SINGLETON)) update.append(">"); } else { String cqlType = mapperToCql.get(mapper.getClass()); if (mapper.cqlCollection().equals(CqlCollection.SINGLETON)) { update.append(cqlType); } else { update.append(mapper.cqlCollectionTag()).append("<"); if (!isNativeCql3Type(cqlType)) update.append("frozen<"); update.append(cqlType); if (!isNativeCql3Type(cqlType)) update.append(">"); update.append(">"); } } if (logger.isDebugEnabled()) { logger.debug("update UDT: " + update.toString()); } QueryProcessor.process(update.toString(), ConsistencyLevel.LOCAL_ONE); } } } return typeName; }
From source file:org.elassandra.index.ElasticSecondaryIndexSearcher.java
License:Apache License
/** * Validates the specified {@link IndexExpression}. It will throw an * {@link org.apache.cassandra.exceptions.InvalidRequestException} if the * provided clause is not valid for the index implementation. * * @param indexExpression/*w ww . j a v a 2 s .c o m*/ * An {@link IndexExpression} to be validated * @throws org.apache.cassandra.exceptions.InvalidRequestException * in case of validation errors */ @Override public void validate(IndexExpression indexExpression) throws InvalidRequestException { logger.debug("indexExpression = {}", indexExpression); throw new InvalidRequestException( "Search through Elastic secondary index is not implemented. Please use the elasticsearch API."); }