Search in sources :

Example 1 with LogicalPlanParsingException

use of org.apache.drill.common.exceptions.LogicalPlanParsingException in project drill by apache.

the class JSONOptions method getWith.

@SuppressWarnings("unchecked")
public <T> T getWith(LogicalPlanPersistence lpPersistance, Class<T> c) {
    try {
        if (opaque != null) {
            final Class<?> opaqueClass = opaque.getClass();
            if (opaqueClass.equals(c)) {
                return (T) opaque;
            } else {
                // e.g. SystemTable$1 for SystemTable.OPTION
                if (c.isEnum()) {
                    final String opaqueName = opaqueClass.getName().replaceAll("\\$\\d+$", "");
                    final String cName = c.getName();
                    if (opaqueName.equals(cName)) {
                        return (T) opaque;
                    }
                }
                throw new IllegalArgumentException(String.format("Attempted to retrieve a option with type of %s.  " + "However, the JSON options carried an opaque value of type %s.", c.getName(), opaqueClass.getName()));
            }
        }
        //logger.debug("Read tree {}", root);
        return lpPersistance.getMapper().treeToValue(root, c);
    } catch (JsonProcessingException e) {
        throw new LogicalPlanParsingException(String.format("Failure while trying to convert late bound " + "json options to type of %s. Reference was originally located at line %d, column %d.", c.getCanonicalName(), location.getLineNr(), location.getColumnNr()), e);
    }
}
Also used : LogicalPlanParsingException(org.apache.drill.common.exceptions.LogicalPlanParsingException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 2 with LogicalPlanParsingException

use of org.apache.drill.common.exceptions.LogicalPlanParsingException in project drill by axbaretto.

the class JSONOptions method getWith.

@SuppressWarnings("unchecked")
public <T> T getWith(LogicalPlanPersistence lpPersistance, Class<T> c) {
    try {
        if (opaque != null) {
            final Class<?> opaqueClass = opaque.getClass();
            if (opaqueClass.equals(c)) {
                return (T) opaque;
            } else {
                // e.g. SystemTable$1 for SystemTable.OPTION
                if (c.isEnum()) {
                    final String opaqueName = opaqueClass.getName().replaceAll("\\$\\d+$", "");
                    final String cName = c.getName();
                    if (opaqueName.equals(cName)) {
                        return (T) opaque;
                    }
                }
                throw new IllegalArgumentException(String.format("Attempted to retrieve a option with type of %s.  " + "However, the JSON options carried an opaque value of type %s.", c.getName(), opaqueClass.getName()));
            }
        }
        // logger.debug("Read tree {}", root);
        return lpPersistance.getMapper().treeToValue(root, c);
    } catch (JsonProcessingException e) {
        throw new LogicalPlanParsingException(String.format("Failure while trying to convert late bound " + "json options to type of %s. Reference was originally located at line %d, column %d.", c.getCanonicalName(), location.getLineNr(), location.getColumnNr()), e);
    }
}
Also used : LogicalPlanParsingException(org.apache.drill.common.exceptions.LogicalPlanParsingException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 3 with LogicalPlanParsingException

use of org.apache.drill.common.exceptions.LogicalPlanParsingException in project drill by apache.

the class JSONOptions method getWith.

@SuppressWarnings("unchecked")
public <T> T getWith(ObjectMapper mapper, Class<T> c) {
    try {
        if (opaque != null) {
            final Class<?> opaqueClass = opaque.getClass();
            if (opaqueClass.equals(c)) {
                return (T) opaque;
            } else {
                // e.g. SystemTable$1 for SystemTable.OPTION
                if (c.isEnum()) {
                    final String opaqueName = opaqueClass.getName().replaceAll("\\$\\d+$", "");
                    final String cName = c.getName();
                    if (opaqueName.equals(cName)) {
                        return (T) opaque;
                    }
                }
                throw new IllegalArgumentException(String.format("Attempted to retrieve a option with type of %s.  " + "However, the JSON options carried an opaque value of type %s.", c.getName(), opaqueClass.getName()));
            }
        }
        // logger.debug("Read tree {}", root);
        return mapper.treeToValue(root, c);
    } catch (JsonProcessingException e) {
        throw new LogicalPlanParsingException(String.format("Failure while trying to convert late bound " + "json options to type of %s. Reference was originally located at line %d, column %d.", c.getCanonicalName(), location.getLineNr(), location.getColumnNr()), e);
    }
}
Also used : LogicalPlanParsingException(org.apache.drill.common.exceptions.LogicalPlanParsingException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 LogicalPlanParsingException (org.apache.drill.common.exceptions.LogicalPlanParsingException)3