Java Code Examples for org.apache.calcite.prepare.Prepare#PreparingTable

The following examples show how to use org.apache.calcite.prepare.Prepare#PreparingTable . 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: FlinkCalciteCatalogReader.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public Prepare.PreparingTable getTable(List<String> names) {
	Prepare.PreparingTable originRelOptTable = super.getTable(names);
	if (originRelOptTable == null) {
		return null;
	} else {
		// Wrap FlinkTable as FlinkRelOptTable to use in query optimization.
		FlinkTable table = originRelOptTable.unwrap(FlinkTable.class);
		if (table != null) {
			return FlinkRelOptTable.create(
				originRelOptTable.getRelOptSchema(),
				originRelOptTable.getRowType(),
				originRelOptTable.getQualifiedName(),
				table);
		} else {
			return originRelOptTable;
		}
	}
}
 
Example 2
Source File: FlinkCalciteCatalogReader.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public Prepare.PreparingTable getTable(List<String> names) {
	Prepare.PreparingTable originRelOptTable = super.getTable(names);
	if (originRelOptTable == null) {
		return null;
	} else {
		// Wrap as FlinkPreparingTableBase to use in query optimization.
		CatalogSchemaTable table = originRelOptTable.unwrap(CatalogSchemaTable.class);
		if (table != null) {
			return toPreparingTable(originRelOptTable.getRelOptSchema(),
				originRelOptTable.getQualifiedName(),
				originRelOptTable.getRowType(),
				table);
		} else {
			return originRelOptTable;
		}
	}
}
 
Example 3
Source File: FlinkCalciteCatalogReaderTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetFlinkPreparingTableBase() {
	// Mock CatalogSchemaTable.
	TableSchema schema = TableSchema.builder().build();
	CatalogSchemaTable mockTable = new CatalogSchemaTable(
		ObjectIdentifier.of("a", "b", "c"),
		CatalogManager.TableLookupResult.permanent(ConnectorCatalogTable.source(
			new TestTableSource(true, schema),
			true), schema),
		FlinkStatistic.UNKNOWN(),
		null,
		true);

	rootSchemaPlus.add(tableMockName, mockTable);
	Prepare.PreparingTable preparingTable = catalogReader
		.getTable(Collections.singletonList(tableMockName));
	assertTrue(preparingTable instanceof FlinkPreparingTableBase);
}
 
Example 4
Source File: MockCatalogReader.java    From calcite with Apache License 2.0 6 votes vote down vote up
private static List<RelCollation> deduceMonotonicity(
    Prepare.PreparingTable table) {
  final List<RelCollation> collationList = new ArrayList<>();

  // Deduce which fields the table is sorted on.
  int i = -1;
  for (RelDataTypeField field : table.getRowType().getFieldList()) {
    ++i;
    final SqlMonotonicity monotonicity =
        table.getMonotonicity(field.getName());
    if (monotonicity != SqlMonotonicity.NOT_MONOTONIC) {
      final RelFieldCollation.Direction direction =
          monotonicity.isDecreasing()
              ? RelFieldCollation.Direction.DESCENDING
              : RelFieldCollation.Direction.ASCENDING;
      collationList.add(
          RelCollations.of(
              new RelFieldCollation(i, direction)));
    }
  }
  return collationList;
}
 
Example 5
Source File: FlinkCalciteCatalogReaderTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetFlinkTable() {
	FlinkTable flinkTableMock = mock(FlinkTable.class);
	when(flinkTableMock.getRowType(typeFactory)).thenReturn(mock(RelDataType.class));
	rootSchemaPlus.add(tableMockName, flinkTableMock);
	Prepare.PreparingTable resultTable = catalogReader.getTable(Arrays.asList(tableMockName));

	assertTrue(resultTable instanceof FlinkRelOptTable);
}
 
Example 6
Source File: FlinkCalciteCatalogReaderTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetNonFlinkTable() {
	Table nonFlinkTableMock = mock(Table.class);
	when(nonFlinkTableMock.getRowType(typeFactory)).thenReturn(mock(RelDataType.class));
	rootSchemaPlus.add(tableMockName, nonFlinkTableMock);
	Prepare.PreparingTable resultTable = catalogReader.getTable(Arrays.asList(tableMockName));
	assertFalse(resultTable instanceof FlinkRelOptTable);
}
 
Example 7
Source File: TestSQLAnalyzer.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@Override
public Prepare.PreparingTable getTable(List<String> names) {
  // Create table used for suggestion
  if (names.contains("TEST_TABLE")) {
    MockTable mockTable = new MockTable("TEST_TABLE", this);
    mockTable.addColumn("colOne", typeFactory.createSqlType(SqlTypeName.INTEGER));
    mockTable.addColumn("colTwo", typeFactory.createSqlType(SqlTypeName.INTEGER));
    return mockTable;
  }

  return null;
}
 
Example 8
Source File: FlinkCalciteCatalogReaderTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetNonFlinkPreparingTableBase() {
	Table nonFlinkTableMock = mock(Table.class);
	when(nonFlinkTableMock.getRowType(typeFactory)).thenReturn(mock(RelDataType.class));
	rootSchemaPlus.add(tableMockName, nonFlinkTableMock);
	Prepare.PreparingTable resultTable = catalogReader
		.getTable(Collections.singletonList(tableMockName));
	assertFalse(resultTable instanceof FlinkPreparingTableBase);
}
 
Example 9
Source File: TestSQLAnalyzer.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
public Prepare.PreparingTable getTableForMember(List<String> names) {
  return getTable(names);
}