2525import org .apache .drill .common .logical .StoragePluginConfig .AuthMode ;
2626import org .apache .drill .common .logical .security .PlainCredentialsProvider ;
2727import org .apache .drill .common .types .TypeProtos ;
28+ import org .apache .drill .common .types .TypeProtos .MinorType ;
2829import org .apache .drill .common .util .DrillFileUtils ;
2930import org .apache .drill .exec .physical .impl .project .ProjectMemoryManager ;
3031import org .apache .drill .exec .physical .impl .project .ProjectRecordBatch ;
@@ -64,6 +65,7 @@ public class TestHttpUDFFunctions extends ClusterTest {
6465
6566 private static final int MOCK_SERVER_PORT = 47771 ;
6667 private static String TEST_JSON_RESPONSE ;
68+ private static String TEST_JSON_PAGE1 ;
6769 private static String DUMMY_URL = "http://localhost:" + MOCK_SERVER_PORT ;
6870 protected static LogFixture logFixture ;
6971 private final static Level CURRENT_LOG_LEVEL = Level .INFO ;
@@ -80,6 +82,7 @@ public static void setup() throws Exception {
8082 .build ();
8183 startCluster (ClusterFixture .builder (dirTestWatcher ));
8284 TEST_JSON_RESPONSE = Files .asCharSource (DrillFileUtils .getResourceAsFile ("/data/simple.json" ), Charsets .UTF_8 ).read ();
85+ TEST_JSON_PAGE1 = Files .asCharSource (DrillFileUtils .getResourceAsFile ("/data/p1.json" ), Charsets .UTF_8 ).read ();
8386
8487 HttpApiConfig mockGithubWithDuplicateParam = HttpApiConfig .builder ()
8588 .url (String .format ("%s/orgs/{org}/repos" , DUMMY_URL ))
@@ -89,8 +92,27 @@ public static void setup() throws Exception {
8992 .requireTail (false )
9093 .build ();
9194
95+ TupleMetadata simpleSchema = new SchemaBuilder ()
96+ .addNullable ("col_1" , MinorType .FLOAT8 )
97+ .addNullable ("col_2" , MinorType .FLOAT8 )
98+ .addNullable ("col_3" , MinorType .FLOAT8 )
99+ .build ();
100+
101+ HttpJsonOptions jsonOptions = new HttpJsonOptions .HttpJsonOptionsBuilder ()
102+ .schema (simpleSchema )
103+ .build ();
104+
105+ HttpApiConfig basicJson = HttpApiConfig .builder ()
106+ .url (String .format ("%s/json" , DUMMY_URL ))
107+ .method ("get" )
108+ .jsonOptions (jsonOptions )
109+ .requireTail (false )
110+ .inputType ("json" )
111+ .build ();
112+
92113 Map <String , HttpApiConfig > configs = new HashMap <>();
93114 configs .put ("github" , mockGithubWithDuplicateParam );
115+ configs .put ("basicJson" , basicJson );
94116
95117 HttpStoragePluginConfig mockStorageConfigWithWorkspace =
96118 new HttpStoragePluginConfig (false , configs , 2 , "globaluser" , "globalpass" , "" ,
@@ -101,6 +123,30 @@ public static void setup() throws Exception {
101123 cluster .defineStoragePlugin ("local" , mockStorageConfigWithWorkspace );
102124 }
103125
126+ @ Test
127+ public void testProvidedSchema () throws Exception {
128+ String sql = "SELECT http_request('local.basicJson') as data FROM (values(1))" ;
129+ try (MockWebServer server = startServer ()) {
130+ server .enqueue (new MockResponse ().setResponseCode (200 ).setBody (TEST_JSON_PAGE1 ));
131+ RowSet results = client .queryBuilder ().sql (sql ).rowSet ();
132+
133+ TupleMetadata expectedSchema = new SchemaBuilder ()
134+ .addMap ("data" )
135+ .addNullable ("col_1" , MinorType .FLOAT8 )
136+ .addNullable ("col_2" , MinorType .FLOAT8 )
137+ .addNullable ("col_3" , MinorType .FLOAT8 )
138+ .resumeSchema ()
139+ .build ();
140+
141+ RowSet expected = new RowSetBuilder (client .allocator (), expectedSchema )
142+ .addRow (singleMap (
143+ mapValue (1.0 , 2.0 , 3.0 )))
144+ .build ();
145+
146+ RowSetUtilities .verify (expected , results );
147+ }
148+ }
149+
104150 @ Test
105151 public void testHttpGetWithNoParams () throws Exception {
106152 try (MockWebServer server = startServer ()) {
0 commit comments