Java Code Examples for org.apache.calcite.schema.SchemaPlus#getParentSchema()

The following examples show how to use org.apache.calcite.schema.SchemaPlus#getParentSchema() . 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: SchemaUtilites.java    From Bats with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: SchemaUtilites.java    From Bats with Apache License 2.0 6 votes vote down vote up
/** 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);
}
 
Example 3
Source File: SqlConverter.java    From Bats with Apache License 2.0 5 votes vote down vote up
private static SchemaPlus rootSchema(SchemaPlus schema) {
  while (true) {
    if (schema.getParentSchema() == null) {
      return schema;
    }
    schema = schema.getParentSchema();
  }
}
 
Example 4
Source File: PlannerContext.java    From flink with Apache License 2.0 5 votes vote down vote up
private SchemaPlus getRootSchema(SchemaPlus schema) {
	if (schema.getParentSchema() == null) {
		return schema;
	} else {
		return getRootSchema(schema.getParentSchema());
	}
}
 
Example 5
Source File: PlannerImpl.java    From Mycat2 with GNU General Public License v3.0 5 votes vote down vote up
private static SchemaPlus rootSchema(SchemaPlus schema) {
    for (; ; ) {
        if (schema.getParentSchema() == null) {
            return schema;
        }
        schema = schema.getParentSchema();
    }
}
 
Example 6
Source File: PlannerContext.java    From flink with Apache License 2.0 5 votes vote down vote up
private SchemaPlus getRootSchema(SchemaPlus schema) {
	if (schema.getParentSchema() == null) {
		return schema;
	} else {
		return getRootSchema(schema.getParentSchema());
	}
}
 
Example 7
Source File: PlannerImpl.java    From calcite with Apache License 2.0 5 votes vote down vote up
private static SchemaPlus rootSchema(SchemaPlus schema) {
  for (;;) {
    if (schema.getParentSchema() == null) {
      return schema;
    }
    schema = schema.getParentSchema();
  }
}
 
Example 8
Source File: SchemaUtilites.java    From Bats with Apache License 2.0 2 votes vote down vote up
/**
 * @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;
}