private static SchemaPlus rootSchema(SchemaPlus schema) { for (;;) { if (schema.getParentSchema() == null) { return schema; } schema = schema.getParentSchema(); } }
private static SchemaPlus rootSchema(SchemaPlus schema) { for (;;) { if (schema.getParentSchema() == null) { return schema; } schema = schema.getParentSchema(); } }
private static SchemaPlus rootSchema(SchemaPlus schema) { while (true) { if (schema.getParentSchema() == null) { return schema; } schema = schema.getParentSchema(); } }
/** * @param schema current schema * @return true if the given <i>schema</i> is root schema. False otherwise. */ public static boolean isRootSchema(SchemaPlus schema) { return schema == null || schema.getParentSchema() == null; }
private static SchemaPlus rootSchema(SchemaPlus schema) { if (schema.getParentSchema() == null) { return schema; } else { return rootSchema(schema.getParentSchema()); } }
/** Returns the path to get to a schema from its root. */ public static Path path(SchemaPlus schema) { List<Pair<String, Schema>> list = new ArrayList<>(); for (SchemaPlus s = schema; s != null; s = s.getParentSchema()) { list.add(Pair.of(s.getName(), s)); } return new PathImpl(ImmutableList.copyOf(Lists.reverse(list))); }
/** Returns the path to get to a schema from its root. */ public static Path path(SchemaPlus schema) { List<Pair<String, Schema>> list = new ArrayList<>(); for (SchemaPlus s = schema; s != null; s = s.getParentSchema()) { list.add(Pair.of(s.getName(), s)); } return new PathImpl(ImmutableList.copyOf(Lists.reverse(list))); }
/** * Search and return schema with given schemaPath. First search in schema tree starting from defaultSchema, * if not found search starting from rootSchema. Root schema tree is derived from the defaultSchema reference. * * @param defaultSchema Reference to the default schema in complete schema tree. * @param schemaPath Schema path to search. * @return SchemaPlus object. */ public static SchemaPlus findSchema(final SchemaPlus defaultSchema, final List<String> schemaPath) { if (schemaPath.size() == 0) { return defaultSchema; } SchemaPlus schema; if ((schema = searchSchemaTree(defaultSchema, schemaPath)) != null) { return schema; } SchemaPlus rootSchema = defaultSchema; while(rootSchema.getParentSchema() != null) { rootSchema = rootSchema.getParentSchema(); } if (rootSchema != defaultSchema && (schema = searchSchemaTree(rootSchema, schemaPath)) != null) { return schema; } return null; }
/** Returns the expression for a schema. */ public static Expression expression(SchemaPlus schema) { return schema.getExpression(schema.getParentSchema(), schema.getName()); }
/** Returns the expression for a schema. */ public static Expression expression(SchemaPlus schema) { return schema.getExpression(schema.getParentSchema(), schema.getName()); }
private ImmutableSet<DataSourceSchema> getDrivers(CalciteSchema tableSchema) { final ImmutableSet.Builder<DataSourceSchema> dsBuilder = new ImmutableSet.Builder<>(); SchemaPlus tableSchemaPlus = tableSchema.plus(); while (tableSchemaPlus != null) { Schema schema = CalciteSchema.from(tableSchemaPlus).schema; if (schema instanceof DataSourceSchema) { dsBuilder.add((DataSourceSchema) schema); } tableSchemaPlus = tableSchemaPlus.getParentSchema(); } return dsBuilder.build(); }
/** Utility method to get the schema path as list for given schema instance. */ public static List<String> getSchemaPathAsList(SchemaPlus schema) { if (isRootSchema(schema)) { return Collections.emptyList(); } List<String> path = Lists.newArrayListWithCapacity(5); while(schema != null) { final String name = schema.getName(); if (!Strings.isNullOrEmpty(name)) { path.add(schema.getName()); } schema = schema.getParentSchema(); } return Lists.reverse(path); }
@Override public Expression getExpression(SchemaPlus schema, String tableName, Class clazz) { return Expressions.field( schema.unwrap(ReflectiveSchema.class).getTargetExpression( schema.getParentSchema(), schema.getName()), field); } }
@Override public Expression getExpression(SchemaPlus schema, String tableName, Class clazz) { return Expressions.field( schema.unwrap(ReflectiveSchema.class).getTargetExpression( schema.getParentSchema(), schema.getName()), field); } }