Java Code Examples for org.apache.calcite.util.Util#throwIfUnchecked()

The following examples show how to use org.apache.calcite.util.Util#throwIfUnchecked() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChainedRelMetadataProvider.java    From Bats with Apache License 2.0 6 votes vote down vote up
public Object invoke(Object proxy, Method method, Object[] args)
    throws Throwable {
  for (Metadata metadata : metadataList) {
    try {
      final Object o = method.invoke(metadata, args);
      if (o != null) {
        return o;
      }
    } catch (InvocationTargetException e) {
      if (e.getCause() instanceof CyclicMetadataException) {
        continue;
      }
      Util.throwIfUnchecked(e.getCause());
      throw new RuntimeException(e.getCause());
    }
  }
  return null;
}
 
Example 2
Source File: CachingSqlStatisticProvider.java    From calcite with Apache License 2.0 6 votes vote down vote up
public boolean isForeignKey(RelOptTable fromTable, List<Integer> fromColumns,
    RelOptTable toTable, List<Integer> toColumns) {
  try {
    final ImmutableList<Object> key =
        ImmutableList.of("isForeignKey",
            fromTable.getQualifiedName(),
            ImmutableIntList.copyOf(fromColumns),
            toTable.getQualifiedName(),
            ImmutableIntList.copyOf(toColumns));
    return (Boolean) cache.get(key,
        () -> provider.isForeignKey(fromTable, fromColumns, toTable,
            toColumns));
  } catch (UncheckedExecutionException | ExecutionException e) {
    Util.throwIfUnchecked(e.getCause());
    throw new RuntimeException(e.getCause());
  }
}
 
Example 3
Source File: ChainedRelMetadataProvider.java    From calcite with Apache License 2.0 6 votes vote down vote up
public Object invoke(Object proxy, Method method, Object[] args)
    throws Throwable {
  for (Metadata metadata : metadataList) {
    try {
      final Object o = method.invoke(metadata, args);
      if (o != null) {
        return o;
      }
    } catch (InvocationTargetException e) {
      if (e.getCause() instanceof CyclicMetadataException) {
        continue;
      }
      Util.throwIfUnchecked(e.getCause());
      throw new RuntimeException(e.getCause());
    }
  }
  return null;
}
 
Example 4
Source File: CachingSqlStatisticProvider.java    From calcite with Apache License 2.0 5 votes vote down vote up
public boolean isKey(RelOptTable table, List<Integer> columns) {
  try {
    final ImmutableList<Object> key =
        ImmutableList.of("isKey", table.getQualifiedName(),
            ImmutableIntList.copyOf(columns));
    return (Boolean) cache.get(key, () -> provider.isKey(table, columns));
  } catch (UncheckedExecutionException | ExecutionException e) {
    Util.throwIfUnchecked(e.getCause());
    throw new RuntimeException(e.getCause());
  }
}
 
Example 5
Source File: CachingLatticeStatisticProvider.java    From Bats with Apache License 2.0 5 votes vote down vote up
public double cardinality(List<Lattice.Column> columns) {
  final List<Double> counts = new ArrayList<>();
  for (Lattice.Column column : columns) {
    try {
      counts.add(cache.get(column));
    } catch (UncheckedExecutionException | ExecutionException e) {
      Util.throwIfUnchecked(e.getCause());
      throw new RuntimeException(e.getCause());
    }
  }
  return (int) Lattice.getRowCount(lattice.getFactRowCount(), counts);
}
 
Example 6
Source File: CachingSqlStatisticProvider.java    From calcite with Apache License 2.0 5 votes vote down vote up
public double tableCardinality(RelOptTable table) {
  try {
    final ImmutableList<Object> key =
        ImmutableList.of("tableCardinality",
            table.getQualifiedName());
    return (Double) cache.get(key,
        () -> provider.tableCardinality(table));
  } catch (UncheckedExecutionException | ExecutionException e) {
    Util.throwIfUnchecked(e.getCause());
    throw new RuntimeException(e.getCause());
  }
}
 
Example 7
Source File: SqlTypeMappingRules.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Put all the type mappings to the {@link Builder}. */
void addAll(Map<SqlTypeName, ImmutableSet<SqlTypeName>> typeMapping) {
  try {
    map.putAll(typeMapping);
  } catch (UncheckedExecutionException e) {
    Util.throwIfUnchecked(e.getCause());
    throw new RuntimeException("populating SqlTypeAssignmentRules", e);
  }
}
 
Example 8
Source File: SqlTypeMappingRules.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Add a map entry to the existing {@link Builder} mapping. */
void add(SqlTypeName fromType, Set<SqlTypeName> toTypes) {
  try {
    map.put(fromType, sets.get(toTypes));
  } catch (UncheckedExecutionException | ExecutionException e) {
    Util.throwIfUnchecked(e.getCause());
    throw new RuntimeException("populating SqlTypeAssignmentRules", e);
  }
}
 
Example 9
Source File: SqlLibraryOperatorTableFactory.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Returns a SQL operator table that contains operators in the given set of
 * libraries. */
public SqlOperatorTable getOperatorTable(Iterable<SqlLibrary> librarySet) {
  try {
    return cache.get(ImmutableSet.copyOf(librarySet));
  } catch (ExecutionException e) {
    Util.throwIfUnchecked(e.getCause());
    throw new RuntimeException("populating SqlOperatorTable for library "
        + librarySet, e);
  }
}
 
Example 10
Source File: SqlPrettyWriter.java    From calcite with Apache License 2.0 5 votes vote down vote up
public Object get(String name) {
  final Method method = getterMethods.get(name);
  try {
    return method.invoke(o);
  } catch (IllegalAccessException | InvocationTargetException e) {
    Util.throwIfUnchecked(e.getCause());
    throw new RuntimeException(e.getCause());
  }
}
 
Example 11
Source File: SqlPrettyWriter.java    From calcite with Apache License 2.0 5 votes vote down vote up
public void set(String name, String value) {
  final Method method = setterMethods.get(name);
  try {
    method.invoke(o, value);
  } catch (IllegalAccessException | InvocationTargetException e) {
    Util.throwIfUnchecked(e.getCause());
    throw new RuntimeException(e.getCause());
  }
}
 
Example 12
Source File: JaninoRelMetadataProvider.java    From calcite with Apache License 2.0 5 votes vote down vote up
synchronized <M extends Metadata, H extends MetadataHandler<M>> H create(
    MetadataDef<M> def) {
  try {
    final Key key = new Key((MetadataDef) def, provider,
        ImmutableList.copyOf(ALL_RELS));
    //noinspection unchecked
    return (H) HANDLERS.get(key);
  } catch (UncheckedExecutionException | ExecutionException e) {
    Util.throwIfUnchecked(e.getCause());
    throw new RuntimeException(e.getCause());
  }
}
 
Example 13
Source File: MetadataFactoryImpl.java    From calcite with Apache License 2.0 5 votes vote down vote up
public <M extends Metadata> M query(RelNode rel, RelMetadataQuery mq,
    Class<M> metadataClazz) {
  try {
    //noinspection unchecked
    final Pair<Class<RelNode>, Class<Metadata>> key =
        (Pair) Pair.of(rel.getClass(), metadataClazz);
    final Metadata apply = cache.get(key).bind(rel, mq);
    return metadataClazz.cast(apply);
  } catch (UncheckedExecutionException | ExecutionException e) {
    Util.throwIfUnchecked(e.getCause());
    throw new RuntimeException(e.getCause());
  }
}
 
Example 14
Source File: CachingLatticeStatisticProvider.java    From calcite with Apache License 2.0 5 votes vote down vote up
public double cardinality(List<Lattice.Column> columns) {
  final List<Double> counts = new ArrayList<>();
  for (Lattice.Column column : columns) {
    try {
      counts.add(cache.get(column));
    } catch (UncheckedExecutionException | ExecutionException e) {
      Util.throwIfUnchecked(e.getCause());
      throw new RuntimeException(e.getCause());
    }
  }
  return (int) Lattice.getRowCount(lattice.getFactRowCount(), counts);
}
 
Example 15
Source File: DruidConnectionImpl.java    From calcite with Apache License 2.0 5 votes vote down vote up
public void close() {
  final Throwable e = throwableHolder.get();
  if (e != null) {
    throwableHolder.set(null);
    Util.throwIfUnchecked(e);
    throw new RuntimeException(e);
  }
}
 
Example 16
Source File: SqlPrettyWriter.java    From Bats with Apache License 2.0 5 votes vote down vote up
public Object get(String name) {
  final Method method = getterMethods.get(name);
  try {
    return method.invoke(o);
  } catch (IllegalAccessException | InvocationTargetException e) {
    Util.throwIfUnchecked(e.getCause());
    throw new RuntimeException(e.getCause());
  }
}
 
Example 17
Source File: SqlPrettyWriter.java    From Bats with Apache License 2.0 5 votes vote down vote up
public void set(String name, String value) {
  final Method method = setterMethods.get(name);
  try {
    method.invoke(o, value);
  } catch (IllegalAccessException | InvocationTargetException e) {
    Util.throwIfUnchecked(e.getCause());
    throw new RuntimeException(e.getCause());
  }
}
 
Example 18
Source File: JaninoRelMetadataProvider.java    From Bats with Apache License 2.0 5 votes vote down vote up
synchronized <M extends Metadata, H extends MetadataHandler<M>> H create(
    MetadataDef<M> def) {
  try {
    final Key key = new Key((MetadataDef) def, provider,
        ImmutableList.copyOf(ALL_RELS));
    //noinspection unchecked
    return (H) HANDLERS.get(key);
  } catch (UncheckedExecutionException | ExecutionException e) {
    Util.throwIfUnchecked(e.getCause());
    throw new RuntimeException(e.getCause());
  }
}
 
Example 19
Source File: MetadataFactoryImpl.java    From Bats with Apache License 2.0 5 votes vote down vote up
public <M extends Metadata> M query(RelNode rel, RelMetadataQuery mq,
    Class<M> metadataClazz) {
  try {
    //noinspection unchecked
    final Pair<Class<RelNode>, Class<Metadata>> key =
        (Pair) Pair.of(rel.getClass(), metadataClazz);
    final Metadata apply = cache.get(key).bind(rel, mq);
    return metadataClazz.cast(apply);
  } catch (UncheckedExecutionException | ExecutionException e) {
    Util.throwIfUnchecked(e.getCause());
    throw new RuntimeException(e.getCause());
  }
}