@@ -30,10 +30,12 @@ func ConnectOpenSearch() error {
3030}
3131
3232type SQLResponse struct {
33- Total int `json:"total"`
33+ Schema []any `json:"schema"`
34+ DataRows [][]any `json:"datarows"`
35+ Total int `json:"total"`
3436}
3537
36- func (b * BackendClient ) ExecuteSQLQuery (ctx context.Context , sql string ) (int , error ) {
38+ func (b * BackendClient ) ExecuteSQLQuery (ctx context.Context , sql string ) (SQLResult , error ) {
3739 baseURL := plugins .PluginCfg ("org.opensearch" , false ).Get ("opensearch" ).String ()
3840 sqlEndpoint := fmt .Sprintf ("%s/_plugins/_sql" , baseURL )
3941
@@ -43,26 +45,30 @@ func (b *BackendClient) ExecuteSQLQuery(ctx context.Context, sql string) (int, e
4345
4446 jsonBody , err := json .Marshal (body )
4547 if err != nil {
46- return 0 , fmt .Errorf ("failed to marshal SQL body: %w" , err )
48+ return SQLResult {} , fmt .Errorf ("failed to marshal SQL body: %w" , err )
4749 }
4850
4951 req , err := http .NewRequestWithContext (ctx , "POST" , sqlEndpoint , bytes .NewBuffer (jsonBody ))
5052 if err != nil {
51- return 0 , fmt .Errorf ("failed to create SQL request: %w" , err )
53+ return SQLResult {} , fmt .Errorf ("failed to create SQL request: %w" , err )
5254 }
5355
5456 req .Header .Set ("Content-Type" , "application/json" )
5557
5658 resp , err := b .httpClient .Do (req )
5759 if err != nil {
58- return 0 , fmt .Errorf ("SQL request failed: %w" , err )
60+ return SQLResult {} , fmt .Errorf ("SQL request failed: %w" , err )
5961 }
6062 defer resp .Body .Close ()
6163
6264 var result SQLResponse
6365 if err := json .NewDecoder (resp .Body ).Decode (& result ); err != nil {
64- return 0 , fmt .Errorf ("failed to decode SQL response: %w" , err )
66+ return SQLResult {} , fmt .Errorf ("failed to decode SQL response: %w" , err )
6567 }
6668
67- return result .Total , nil
69+ // Convertir a tu tipo interno
70+ return SQLResult {
71+ Rows : result .DataRows ,
72+ Count : result .Total ,
73+ }, nil
6874}
0 commit comments