Skip to content

Commit

Permalink
Persistence: Categorise errors among data, internal and transient err…
Browse files Browse the repository at this point in the history
…ors (#2925)
  • Loading branch information
prasar-ashutosh authored Aug 6, 2024
1 parent 620c28e commit 119652c
Show file tree
Hide file tree
Showing 26 changed files with 508 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2024 Goldman Sachs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package org.finos.legend.engine.persistence.components.exception;

public class EmptyBatchException extends PersistenceException
{

@Override
public boolean isRecoverable()
{
return false;
}

public EmptyBatchException(String message)
{
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2024 Goldman Sachs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package org.finos.legend.engine.persistence.components.exception;

public class JsonReadOrWriteException extends PersistenceException
{
public JsonReadOrWriteException(String message, Throwable cause)
{
super(message, cause);
}

@Override
public boolean isRecoverable()
{
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2024 Goldman Sachs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package org.finos.legend.engine.persistence.components.exception;

public abstract class PersistenceException extends RuntimeException
{

public abstract boolean isRecoverable();

public PersistenceException(String message, Throwable cause)
{
super(message, cause);
}

public PersistenceException(String message)
{
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ default void validate()
{
if (filePatterns().size() > 0 && filePaths().size() > 0)
{
throw new IllegalArgumentException("Cannot build StagedFilesDatasetProperties, Only one out of filePatterns and filePaths should be provided");
throw new IllegalStateException("Cannot build StagedFilesDatasetProperties, Only one out of filePatterns and filePaths should be provided");
}
if (filePatterns().size() == 0 && filePaths().size() == 0)
{
throw new IllegalArgumentException("Cannot build StagedFilesDatasetProperties, Either one of filePatterns and filePaths must be provided");
throw new IllegalStateException("Cannot build StagedFilesDatasetProperties, Either one of filePatterns and filePaths must be provided");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import org.finos.legend.engine.persistence.components.common.Datasets;
import org.finos.legend.engine.persistence.components.common.Resources;
import org.finos.legend.engine.persistence.components.exception.EmptyBatchException;
import org.finos.legend.engine.persistence.components.ingestmode.UnitemporalSnapshot;
import org.finos.legend.engine.persistence.components.ingestmode.emptyhandling.DeleteTargetDataAbstract;
import org.finos.legend.engine.persistence.components.ingestmode.emptyhandling.EmptyDatasetHandlingVisitor;
Expand Down Expand Up @@ -277,7 +278,7 @@ public LogicalPlan visitDeleteTargetData(DeleteTargetDataAbstract deleteTargetDa
@Override
public LogicalPlan visitFailEmptyBatch(FailEmptyBatchAbstract failEmptyBatchAbstract)
{
throw new RuntimeException("Encountered an Empty Batch, FailEmptyBatch is enabled, so failing the batch!");
throw new EmptyBatchException("Encountered an Empty Batch, FailEmptyBatch is enabled, so failing the batch!");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.finos.legend.engine.persistence.components.common.DatasetFilter;
import org.finos.legend.engine.persistence.components.common.Datasets;
import org.finos.legend.engine.persistence.components.common.OptimizationFilter;
import org.finos.legend.engine.persistence.components.exception.JsonReadOrWriteException;
import org.finos.legend.engine.persistence.components.ingestmode.IngestMode;
import org.finos.legend.engine.persistence.components.ingestmode.deduplication.*;
import org.finos.legend.engine.persistence.components.ingestmode.versioning.*;
Expand Down Expand Up @@ -322,7 +323,7 @@ public static Optional<StringValue> getStringValueFromMap(Map<String, Object> ma
}
catch (JsonProcessingException e)
{
throw new RuntimeException(e);
throw new JsonReadOrWriteException(e.getMessage(), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.finos.legend.engine.persistence.components.exception.JsonReadOrWriteException;
import org.finos.legend.engine.persistence.components.executor.DigestInfo;
import org.finos.legend.engine.persistence.components.executor.Executor;
import org.finos.legend.engine.persistence.components.executor.ResultData;
Expand Down Expand Up @@ -73,7 +74,7 @@ public void importData(ExternalDatasetReference externalDatasetReference, Digest
}
catch (JsonProcessingException e)
{
throw new RuntimeException(e);
throw new JsonReadOrWriteException(e.getMessage(), e);
}

for (Map<String, Object> row : rows)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,16 @@

package org.finos.legend.engine.persistence.components.schemaevolution;

public class IncompatibleSchemaChangeException extends RuntimeException
import org.finos.legend.engine.persistence.components.exception.PersistenceException;

public class IncompatibleSchemaChangeException extends PersistenceException
{
@Override
public boolean isRecoverable()
{
return false;
}

public IncompatibleSchemaChangeException(String message)
{
super(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public List<TabularData> executePhysicalPlanAndGetResults(SqlPlan physicalPlan)
@Override
public List<TabularData> executePhysicalPlanAndGetResults(SqlPlan physicalPlan, int rows)
{
throw new RuntimeException("Not implemented for Big Query");
throw new UnsupportedOperationException("Not implemented for Big Query");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static BigQueryHelper of(BigQuery bigQuery)
{
return new BigQueryHelper(bigQuery);
}
throw new RuntimeException("Sink initialized without connection can only be used for SQL generation APIs, but used with ingestion API");
throw new IllegalStateException("Sink initialized without connection can only be used for SQL generation APIs, but used with ingestion API");
}

private BigQueryHelper(BigQuery bigQuery)
Expand Down Expand Up @@ -371,7 +371,7 @@ public void executeStatements(List<String> sqls)
@Override
public List<Map<String, Object>> executeQuery(String sql, int rows)
{
throw new RuntimeException("Not implemented for Big Query");
throw new UnsupportedOperationException("Not implemented for Big Query");
}

public void executeStatementsInANewTransaction(List<String> sqls)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.finos.legend.engine.persistence.components.planner.Planner;
import org.finos.legend.engine.persistence.components.relational.CaseConversion;
import org.finos.legend.engine.persistence.components.relational.SqlPlan;
import org.finos.legend.engine.persistence.components.exception.JsonReadOrWriteException;
import org.finos.legend.engine.persistence.components.relational.sql.TabularData;
import org.finos.legend.engine.persistence.components.relational.sqldom.SqlGen;
import org.finos.legend.engine.persistence.components.transformer.Transformer;
Expand Down Expand Up @@ -361,7 +362,7 @@ public static String buildErrorRecord(List<String> allColumns, Map<String, Objec
}
catch (JsonProcessingException e)
{
throw new RuntimeException(e);
throw new JsonReadOrWriteException(e.getMessage(), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import org.eclipse.collections.api.tuple.Pair;
import org.finos.legend.engine.persistence.components.common.*;
import org.finos.legend.engine.persistence.components.exception.JsonReadOrWriteException;
import org.finos.legend.engine.persistence.components.executor.DigestInfo;
import org.finos.legend.engine.persistence.components.executor.Executor;
import org.finos.legend.engine.persistence.components.importer.Importer;
Expand Down Expand Up @@ -653,7 +654,7 @@ private List<DataError> performDryRun()
}
else
{
throw new RuntimeException("Dry Run not supported for this ingest Mode : " + enrichedIngestMode.getClass().getSimpleName());
throw new UnsupportedOperationException("Dry Run not supported for this ingest Mode : " + enrichedIngestMode.getClass().getSimpleName());
}
}

Expand Down Expand Up @@ -927,7 +928,7 @@ private String writeValueAsString(Map<StatisticName, Object> statisticByName)
}
catch (JsonProcessingException e)
{
throw new RuntimeException(e);
throw new JsonReadOrWriteException(e.getMessage(), e);
}
}

Expand All @@ -939,7 +940,7 @@ private Map<StatisticName, Object> readValueAsMap(String batchStatistics)
}
catch (JsonProcessingException e)
{
throw new RuntimeException(e);
throw new JsonReadOrWriteException(e.getMessage(), e);
}
}

Expand Down Expand Up @@ -1019,7 +1020,7 @@ private Map<String, PlaceholderValue> extractPlaceHolderKeyValues(Datasets datas
}
catch (JsonProcessingException e)
{
throw new IllegalStateException("Unable to parse additional metadata");
throw new JsonReadOrWriteException("Unable to parse additional metadata", e);
}

// Handle batch timestamp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2024 Goldman Sachs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package org.finos.legend.engine.persistence.components.relational.exception;

public class ConnectionException extends SqlExecutionException
{

/*
SQL STATE: 08***
*/

public ConnectionException(String message, Throwable cause, String SQLState, int vendorCode)
{
super(message, cause, SQLState, vendorCode);
}

@Override
public boolean isRecoverable()
{
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2024 Goldman Sachs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package org.finos.legend.engine.persistence.components.relational.exception;

public class ConstraintViolationException extends SqlExecutionException
{

/*
SQL STATE: 23***
*/

public ConstraintViolationException(String message, Throwable cause, String SQLState, int vendorCode)
{
super(message, cause, SQLState, vendorCode);
}

@Override
public boolean isRecoverable()
{
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@

package org.finos.legend.engine.persistence.components.relational.exception;

import org.finos.legend.engine.persistence.components.exception.PersistenceException;
import org.finos.legend.engine.persistence.components.relational.api.DataError;

import java.util.List;

public class DataQualityException extends RuntimeException
public class DataQualityException extends PersistenceException
{
private List<DataError> dataErrors;

Expand All @@ -32,4 +33,10 @@ public DataQualityException(String message, List<DataError> dataErrors)
super(message);
this.dataErrors = dataErrors;
}

@Override
public boolean isRecoverable()
{
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2024 Goldman Sachs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package org.finos.legend.engine.persistence.components.relational.exception;

public class DataRelatedException extends SqlExecutionException
{

/*
SQL STATE: 20***, 21***, 22***
*/

public DataRelatedException(String message, Throwable cause, String SQLState, int vendorCode)
{
super(message, cause, SQLState, vendorCode);
}

@Override
public boolean isRecoverable()
{
return false;
}
}
Loading

0 comments on commit 119652c

Please sign in to comment.