53
53
import org .apache .calcite .schema .impl .ViewTableMacro ;
54
54
import org .apache .calcite .sql .SqlDialect ;
55
55
import org .apache .calcite .sql .SqlExplainLevel ;
56
+ import org .apache .calcite .sql .fun .SqlGeoFunctions ;
56
57
import org .apache .calcite .sql .type .SqlTypeName ;
57
58
import org .apache .calcite .sql .validate .SqlConformanceEnum ;
58
59
import org .apache .calcite .sql .validate .SqlValidatorException ;
@@ -750,6 +751,7 @@ public static SchemaPlus addSchema(SchemaPlus rootSchema, SchemaSpec schema) {
750
751
final SchemaPlus scott ;
751
752
final ConnectionSpec cs ;
752
753
final DataSource dataSource ;
754
+ final ImmutableList <String > emptyPath = ImmutableList .of ();
753
755
switch (schema ) {
754
756
case REFLECTIVE_FOODMART :
755
757
return rootSchema .add (schema .schemaName ,
@@ -793,16 +795,37 @@ public static SchemaPlus addSchema(SchemaPlus rootSchema, SchemaSpec schema) {
793
795
foodmart = addSchemaIfNotExists (rootSchema , SchemaSpec .JDBC_FOODMART );
794
796
return rootSchema .add ("foodmart2" , new CloneSchema (foodmart ));
795
797
case GEO :
796
- ModelHandler .addFunctions (rootSchema , null , ImmutableList . of () ,
798
+ ModelHandler .addFunctions (rootSchema , null , emptyPath ,
797
799
GeoFunctions .class .getName (), "*" , true );
800
+ ModelHandler .addFunctions (rootSchema , null , emptyPath ,
801
+ SqlGeoFunctions .class .getName (), "*" , true );
798
802
final SchemaPlus s =
799
803
rootSchema .add (schema .schemaName , new AbstractSchema ());
800
- ModelHandler .addFunctions (s , "countries" , ImmutableList . of () ,
804
+ ModelHandler .addFunctions (s , "countries" , emptyPath ,
801
805
CountriesTableFunction .class .getName (), null , false );
802
806
final String sql = "select * from table(\" countries\" (true))" ;
803
807
final ViewTableMacro viewMacro = ViewTable .viewMacro (rootSchema , sql ,
804
- ImmutableList .of ("GEO" ), ImmutableList . of () , false );
808
+ ImmutableList .of ("GEO" ), emptyPath , false );
805
809
s .add ("countries" , viewMacro );
810
+
811
+ ModelHandler .addFunctions (s , "states" , emptyPath ,
812
+ StatesTableFunction .class .getName (), "states" , false );
813
+ final String sql2 = "select \" name\" ,\n "
814
+ + " ST_PolyFromText(\" geom\" ) as \" geom\" \n "
815
+ + "from table(\" states\" (true))" ;
816
+ final ViewTableMacro viewMacro2 = ViewTable .viewMacro (rootSchema , sql2 ,
817
+ ImmutableList .of ("GEO" ), emptyPath , false );
818
+ s .add ("states" , viewMacro2 );
819
+
820
+ ModelHandler .addFunctions (s , "parks" , emptyPath ,
821
+ StatesTableFunction .class .getName (), "parks" , false );
822
+ final String sql3 = "select \" name\" ,\n "
823
+ + " ST_PolyFromText(\" geom\" ) as \" geom\" \n "
824
+ + "from table(\" parks\" (true))" ;
825
+ final ViewTableMacro viewMacro3 = ViewTable .viewMacro (rootSchema , sql3 ,
826
+ ImmutableList .of ("GEO" ), emptyPath , false );
827
+ s .add ("parks" , viewMacro3 );
828
+
806
829
return s ;
807
830
case HR :
808
831
return rootSchema .add (schema .schemaName ,
@@ -835,7 +858,7 @@ public static SchemaPlus addSchema(SchemaPlus rootSchema, SchemaSpec schema) {
835
858
+ " ('Grace', 60, 'F'),\n "
836
859
+ " ('Wilma', cast(null as integer), 'F'))\n "
837
860
+ " as t(ename, deptno, gender)" ,
838
- ImmutableList . of () , ImmutableList .of ("POST" , "EMP" ),
861
+ emptyPath , ImmutableList .of ("POST" , "EMP" ),
839
862
null ));
840
863
post .add ("DEPT" ,
841
864
ViewTable .viewMacro (post ,
@@ -844,7 +867,7 @@ public static SchemaPlus addSchema(SchemaPlus rootSchema, SchemaSpec schema) {
844
867
+ " (20, 'Marketing'),\n "
845
868
+ " (30, 'Engineering'),\n "
846
869
+ " (40, 'Empty')) as t(deptno, dname)" ,
847
- ImmutableList . of () , ImmutableList .of ("POST" , "DEPT" ),
870
+ emptyPath , ImmutableList .of ("POST" , "DEPT" ),
848
871
null ));
849
872
post .add ("DEPT30" ,
850
873
ViewTable .viewMacro (post ,
@@ -860,7 +883,7 @@ public static SchemaPlus addSchema(SchemaPlus rootSchema, SchemaSpec schema) {
860
883
+ " (120, 'Wilma', 20, 'F', CAST(NULL AS VARCHAR(20)), 1, 5, UNKNOWN, TRUE, DATE '2005-09-07'),\n "
861
884
+ " (130, 'Alice', 40, 'F', 'Vancouver', 2, CAST(NULL AS INT), FALSE, TRUE, DATE '2007-01-01'))\n "
862
885
+ " as t(empno, name, deptno, gender, city, empid, age, slacker, manager, joinedat)" ,
863
- ImmutableList . of () , ImmutableList .of ("POST" , "EMPS" ),
886
+ emptyPath , ImmutableList .of ("POST" , "EMPS" ),
864
887
null ));
865
888
post .add ("TICKER" ,
866
889
ViewTable .viewMacro (post ,
0 commit comments