Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import java.util.List;
import java.util.Optional;
import java.util.Set;

import org.eclipse.daanse.mdx.model.api.MdxStatement;
import org.eclipse.daanse.mdx.parser.api.MdxParser;
Expand Down Expand Up @@ -112,31 +111,27 @@ public QueryComponent parseStatement(

MdxParser parser;
try {
parser = getContext().getMdxParserProvider().newParser(queryToParse, funTable.getPropertyWords());
MdxStatement mdxStatement = parser.parseMdxStatement();
return getQueryProvider().createQuery(statement, mdxStatement, strictValidation);
parser = getContext().getMdxParserProvider().newParser(queryToParse, funTable.getPropertyWords());
MdxStatement mdxStatement = parser.parseMdxStatement();
return getQueryProvider().createQuery(statement, mdxStatement, strictValidation);
} catch (MdxParserException mdxPE) {
try {
parser = getContext().getMdxParserProvider().newParser(queryToParse, Set.of());
MdxStatement mdxStatement = parser.parseDMVStatement();
return getQueryProvider().createQuery(statement, mdxStatement, strictValidation);
} catch (MdxParserException mdxPE1) {
Optional<SqlGuardFactory> oSqlGuardFactory = getContext().getSqlGuardFactory();
if (oSqlGuardFactory.isEmpty()) {

Optional<SqlGuardFactory> oSqlGuardFactory = getContext().getSqlGuardFactory();
if (oSqlGuardFactory.isEmpty()) {
throw new FailedToParseQueryException(queryToParse, mdxPE);
} else {
List<DatabaseSchema> ds = (List<DatabaseSchema>) this.getCatalogReader().getDatabaseSchemas();
org.eclipse.daanse.sql.guard.api.elements.DatabaseCatalog dc = new DatabaseCatalogImpl("", ds);
SqlGuard guard = oSqlGuardFactory.get().create("", "", dc, List.of(), this.getContext().getDialect());
// TODO add white list functions
try {
String sanetizedSql = guard.guard(queryToParse);
return new SqlQueryImpl(sanetizedSql, getContext().getDataSource());
} catch (UnparsableStatementGuardException uex) {
// when can´t be parse then we decide to throw the exception of MDX
throw new FailedToParseQueryException(queryToParse, mdxPE);
} else {
List<DatabaseSchema> ds = (List<DatabaseSchema>) this.getCatalogReader().getDatabaseSchemas();
org.eclipse.daanse.sql.guard.api.elements.DatabaseCatalog dc = new DatabaseCatalogImpl("", ds);
SqlGuard guard = oSqlGuardFactory.get().create("", "", dc, List.of(), this.getContext().getDialect() ); //TODO add white list functions
try {
String sanetizedSql= guard.guard(queryToParse);
return new SqlQueryImpl(sanetizedSql, getContext().getDataSource());
} catch (UnparsableStatementGuardException uex) {
// when can´t be parse then we decide to throw the exception of MDX
throw new FailedToParseQueryException(queryToParse, mdxPE);
} catch (GuardException guasdEx) {
throw new FailedToParseQueryException(queryToParse, guasdEx);
}
} catch (GuardException guasdEx) {
throw new FailedToParseQueryException(queryToParse, guasdEx);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ public ContextsSupplyerImpl(ContextGroup contextsGroup) {

@Override
public List<Catalog> get(Optional<String> sessionId) {
return getContexts().stream().map(context -> getConnection(sessionId, context.getName())).map(Connection::getCatalog).toList();
return getContexts().stream().map(context -> getConnection(sessionId, context.getName()))
.map(Connection::getCatalog).toList();
}

@Override
public Optional<Catalog> tryGetFirstByName(String catalogName, Optional<String> sessionId) {
public Optional<Catalog> tryGetFirstByName(String catalogName, Optional<String> sessionId) {
return Optional.of(getConnection(sessionId, catalogName).getCatalog());
}

Expand All @@ -64,12 +65,20 @@ public Map<String, Map<String, Connection>> getSessionCache() {
@Override
public Connection getConnection(Optional<String> sessionId, String catalogName) {
if (sessionId.isPresent() && sessionCache.containsKey(sessionId.get())) {
Map<String, Connection> connectionMap = sessionCache.get(sessionId.get());
Map<String, Connection> connectionMap = sessionCache.get(sessionId.get());
if (connectionMap.containsKey(catalogName)) {
return connectionMap.get(catalogName);
}
} else {
Connection connection = getContexts().stream().filter(c -> c.getName().equals(catalogName)).findFirst()
.map(context -> {
Connection con = context.getConnection(new ConnectionProps(List.of()));
return con;
}).orElseThrow(() -> new RuntimeException("No context found for catalog " + catalogName));
return connection;
}
throw new RuntimeException("Connection is absent in cache for session " + sessionId + " for catalog " + catalogName);
throw new RuntimeException(
"Connection is absent in cache for session " + sessionId + " for catalog " + catalogName);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,11 @@
import org.eclipse.daanse.xmla.model.record.mddataset.RowSetR;
import org.eclipse.daanse.xmla.model.record.mddataset.RowSetRowR;
import org.eclipse.daanse.xmla.model.record.xmla_empty.EmptyresultR;
import org.slf4j.Logger;

public class OlapExecuteService implements ExecuteService {

private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(OlapExecuteService.class);
private static final String MDX_CUBE_0_NOT_FOUND = "MDX cube ''{0}'' not found";
public static final String SESSION_ID = "sessionId";
public static final String CODE3238658121 = "3238658121";
Expand Down Expand Up @@ -247,14 +249,19 @@ public ClearCacheResponse clearCache(ClearCacheRequest clearCacheRequest, Reques
public StatementResponse statement(StatementRequest statementRequest, RequestMetaData metaData,
UserRolePrincipal userRolePrincipal) {

String statement = statementRequest.command().statement();
if (statement == null || statement.isBlank()) {
LOGGER.warn("Empty statement received");
return new StatementResponseR(null, null);
}

Optional<String> oCatalog = statementRequest.properties().catalog();

if (oCatalog.isPresent()) {
String catalogName = oCatalog.get();
Optional<Context<?>> oContext = contextsListSupplyer.getContexts().stream()
.filter(ctx -> catalogName.equals(ctx.getName())).findAny();
Context context = oContext.get();
String statement = statementRequest.command().statement();
if (statement != null && statement.length() > 0) {
Locale locale = getLocale(statementRequest.properties());
Connection connection = context.getConnection(new ConnectionProps(RoleUtils.getRoles(contextsListSupplyer, r -> userRolePrincipal.hasRole(r)), locale));
QueryComponent queryComponent = connection.parseStatement(statement);
Expand All @@ -264,10 +271,8 @@ public StatementResponse statement(StatementRequest statementRequest, RequestMet
} else if (queryComponent instanceof CalculatedFormula calculatedFormula) {
return executeCalculatedFormula(connection, calculatedFormula);
} else if (queryComponent instanceof DmvQuery dmvQuery) {
return executeDmvQuery(connection, dmvQuery, metaData, statementRequest); // toto:
// remove
// userRolePrincipal,
// metaData,
return executeDmvQuery(connection, dmvQuery, metaData, statementRequest);
// TODO: remove userRolePrincipal, metaData,
} else if (queryComponent instanceof Refresh refresh) {
return executeRefresh(connection, refresh);
} else if (queryComponent instanceof Update update) {
Expand All @@ -280,28 +285,53 @@ public StatementResponse statement(StatementRequest statementRequest, RequestMet
} else if (queryComponent instanceof SqlQuery sqlQuery) {
return executeSqlQuery(sqlQuery);
}
}

} else {
String statement = statementRequest.command().statement();
if (statement != null && statement.length() > 0 && contextsListSupplyer.getContexts() != null
&& !contextsListSupplyer.getContexts().isEmpty()) {
if (contextsListSupplyer.getContexts() != null && !contextsListSupplyer.getContexts().isEmpty()) {
//TODO: aggregate word from all statements?
//or do we have a default context?
Connection connection = contextsListSupplyer.getContexts().get(0).getConnection(new ConnectionProps(RoleUtils.getRoles(contextsListSupplyer, r -> userRolePrincipal.hasRole(r))));
QueryComponent queryComponent = connection.parseStatement(statement);
if (queryComponent instanceof DmvQuery dmvQuery
&& dmvQuery.getTableName().equals(OperationNames.DBSCHEMA_CATALOGS)) {
List<DbSchemaCatalogsResponseRow> dbSchemaCatalogsResponseRowSetList = new ArrayList<DbSchemaCatalogsResponseRow>();
for (Context c : contextsListSupplyer.getContexts()) {
dbSchemaCatalogsResponseRowSetList.add(dbSchemaService.dbSchemaCatalogsRow(c));
if (queryComponent instanceof DmvQuery dmvQuery) {

System.out.println("!!!! use sesscioncach to et the open connection is session exists");
String tableName = dmvQuery.getTableName();
if (tableName.equalsIgnoreCase(OperationNames.DBSCHEMA_CATALOGS)) {
List<DbSchemaCatalogsResponseRow> dbSchemaCatalogsResponseRowSetList = new ArrayList<DbSchemaCatalogsResponseRow>();
for (Context c : contextsListSupplyer.getContexts()) {
dbSchemaCatalogsResponseRowSetList.add(dbSchemaService.dbSchemaCatalogsRow(c));
}
RowSetR rowSet = DiscoveryResponseConvertor
.dbSchemaCatalogsResponseRowToRowSet(dbSchemaCatalogsResponseRowSetList);
return new StatementResponseR(null, filterRowSetByColumns(rowSet, dmvQuery.getColumns(),
dmvQuery.getWhereExpression(), statementRequest.parameters()));
} else if (tableName.equalsIgnoreCase(OperationNames.MDSCHEMA_CUBES)) {
// special case for MDSCHEMA_CUBES without catalog : return from all catalogs
List<RowSetRow> rsrs = new ArrayList<>();
for (Context<?> c : contextsListSupplyer.getContexts()) {
Connection conn = c.getConnection(new ConnectionProps(
RoleUtils.getRoles(contextsListSupplyer, r -> userRolePrincipal.hasRole(r))));
Catalog catalog = conn.getCatalog();
System.out.println("!!!!!!!!!!!!!!!!USE Catalogreader to enforce the roles");
MdSchemaCubesRequest mdSchemaCubesRequest = new MdSchemaCubesRequestR(
(PropertiesR) statementRequest.properties(),
new MdSchemaCubesRestrictionsR(null, empty(), empty(), empty(), empty(), empty()));
RowSetR rowSet = DiscoveryResponseConvertor.mdSchemaCubesResponseRowToRowSet(
mdSchemaService.mdSchemaCubes(mdSchemaCubesRequest, metaData));
rsrs.addAll(rowSet.rowSetRows());
}
RowSetR combinedRowSet = new RowSetR(rsrs);
return new StatementResponseR(null, filterRowSetByColumns(combinedRowSet, dmvQuery.getColumns(),
dmvQuery.getWhereExpression(), statementRequest.parameters()));

}
RowSetR rowSet = DiscoveryResponseConvertor
.dbSchemaCatalogsResponseRowToRowSet(dbSchemaCatalogsResponseRowSetList);
return new StatementResponseR(null, filterRowSetByColumns(rowSet, dmvQuery.getColumns(),
dmvQuery.getWhereExpression(), statementRequest.parameters()));

}
}
// here
}
}

return new StatementResponseR(null, null);

}

private Locale getLocale(Properties properties) {
Expand Down
Loading