Skip to content

Commit

Permalink
added flag for auto-generated queries, e.g. mql non-existing collections
Browse files Browse the repository at this point in the history
  • Loading branch information
datomo committed Apr 22, 2024
1 parent f81f3b9 commit b538ffa
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public List<ImplementationContext> anyPrepareQuery( QueryContext context, Statem
throw new GenericRuntimeException( String.format( "%s query is empty", context.getLanguage().serializedName() ) );
}

parsedQueries = context.getLanguage().splitter().apply( context );
parsedQueries = context.getLanguage().parser().apply( context );
} catch ( Throwable e ) {
log.warn( "Error on preparing query: {}", e.getMessage() );
if ( transaction.isAnalyze() ) {
Expand All @@ -133,7 +133,7 @@ public List<ImplementationContext> anyPrepareQuery( QueryContext context, Statem
try {
// test if parsing was successful
if ( parsed.getQueryNode().isEmpty() ) {
Exception e = new GenericRuntimeException( "Error during parsing of query \"" + context.getQuery() + "\"" );
Exception e = new GenericRuntimeException( "Error during parsing of query \"%s\"".formatted( context.getQuery() ) );
return handleParseException( statement, parsed, transaction, e, implementationContexts );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public record QueryLanguage(
@Nullable ParserFactory factory,
@NotNull Supplier<Processor> processorSupplier,
@Nullable BiFunction<Context, Snapshot, Validator> validatorSupplier,
@NotNull Function<QueryContext, List<ParsedQueryContext>> splitter,
@NotNull Function<QueryContext, List<ParsedQueryContext>> parser,
@NotNull Function<QueryContext, QueryContext> limitRemover
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public class QueryContext {
@Builder.Default
boolean isAnalysed = false;

@Builder.Default
boolean isAutoGenerated = false;

@Builder.Default
boolean usesCache = true;

Expand Down Expand Up @@ -100,6 +103,7 @@ public static ParsedQueryContext fromQuery( String query, Node queryNode, QueryC
return ParsedQueryContext.builder()
.query( query )
.queryNode( queryNode )
.isAutoGenerated( context.isAutoGenerated )
.language( context.language )
.isAnalysed( context.isAnalysed )
.usesCache( context.usesCache )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public interface Transaction {

void updateAccessMode( AccessMode accessCandidate );

TransactionManager getTransactionManager();

/**
* Flavor, how multimedia results should be returned from a store.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class TransactionImpl implements Transaction, Comparable<Object> {
private final LogicalUser user;
@Getter
private final LogicalNamespace defaultNamespace;

@Getter
private final TransactionManagerImpl transactionManager;

@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ private static List<ParsedQueryContext> anyQuerySplitter( QueryContext context )
.namespaceId( context.getNamespaceId() )
.transactionManager( context.getTransactionManager() )
.origin( context.getOrigin() )
.isAutoGenerated( true )
.informationTarget( context.getInformationTarget() )
.build() ).map( LanguageManager::toQueryNodes ).toList();

Expand All @@ -137,11 +138,6 @@ private static List<ParsedQueryContext> anyQuerySplitter( QueryContext context )
}


public String preprocessing( String query, QueryContext context ) {
return query;
}


public static void registerOperators() {
if ( isInit ) {
throw new GenericRuntimeException( "Mql operators were already registered." );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public static void implement( PIStatement piStatement ) {
.query( piStatement.getQuery() )
.language( piStatement.getLanguage() )
.namespaceId( piStatement.getNamespace().id )
.transactionManager( piStatement.getTransaction().getTransactionManager() )
.origin( ORIGIN )
.build();
List<ImplementationContext> implementations = LanguageManager.getINSTANCE().anyPrepareQuery( context, statement );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public QueryContext getContext( String query ) {
public void testQueryWithSemicolon() {
QueryContext context = getContext( "SELECT * FROM employee WHERE ename = ';'" );

List<ParsedQueryContext> res = sql.splitter().apply( context );
List<ParsedQueryContext> res = sql.parser().apply( context );
assertEquals( 1, res.size() );
}

Expand All @@ -62,7 +62,7 @@ public void testQueryWithSemicolon() {
public void testTwoQueries() {
QueryContext context = getContext( "SELECT * FROM employee WHERE ename = 'a'; SELECT * FROM employee WHERE ename = 'b'" );

List<ParsedQueryContext> res = sql.splitter().apply( context );
List<ParsedQueryContext> res = sql.parser().apply( context );
assertEquals( 2, res.size() );
}

Expand All @@ -71,7 +71,7 @@ public void testTwoQueries() {
public void testTwoQueriesWithSemicolon() {
QueryContext context = getContext( "SELECT * FROM employee WHERE ename = ';'; SELECT * FROM employee WHERE ename = ';'" );

List<ParsedQueryContext> res = sql.splitter().apply( context );
List<ParsedQueryContext> res = sql.parser().apply( context );
assertEquals( 2, res.size() );
}

Expand Down

0 comments on commit b538ffa

Please sign in to comment.