google / zetasql

ZetaSQL - Analyzer Framework for SQL
Apache License 2.0
2.32k stars 219 forks source link

How to use? #4

Open gradient-zero opened 5 years ago

gradient-zero commented 5 years ago

Could you easily explain how to use? How to connect the parser to my Command line interface Is there any sample? Thanks

MartinSahlen commented 4 years ago

@hidarapaneni Hello! You probably forgot to include the channel dependency in your pom / gradle: https://mvnrepository.com/artifact/com.google.zetasql/zetasql-jni-channel

hidarapaneni commented 4 years ago

thanks for responding @MartinSahlen .. i did include in my dependencies..in fact I included all dependencies under zetasql.. five of them

MartinSahlen commented 4 years ago

@hidarapaneni Don't think it matters to your case, but you only need to include the zetasql-client and zetasql-jni-channel, the other ones are just transitive dependencies. What platform are you running on? It will not work on windows - just making sure you are aware of that.

hidarapaneni commented 4 years ago

@MartinSahlen .. I tried with those deps. alone but no luck also i am running on Linux..

MartinSahlen commented 4 years ago

@hidarapaneni I assume you're running on Ubuntu 1804 as they state in the docs? I'm running this on Mac OS (Darwin) and here the code I'm using (it's kotlin but principles apply), tested with v2020.07.1:

package zeta.parser

import com.google.zetasql.Analyzer
import com.google.zetasql.SqlException
import com.google.zetasql.SqlFormatter
import io.micronaut.http.HttpResponse
import io.micronaut.http.HttpStatus
import io.micronaut.http.MediaType
import io.micronaut.http.annotation.Body
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Post
import io.micronaut.runtime.Micronaut

@Controller()
class ZetaController {
    private val formatter: SqlFormatter = SqlFormatter()

    @Post(uri="/extract-table-names", consumes =[MediaType.TEXT_PLAIN], produces = [MediaType.APPLICATION_JSON])
    fun extractTableNames(@Body sql: String): HttpResponse<Map<String, Any?>>   {
        var result: List<List<String>>? = null
        var error: String? = null
        var status = HttpStatus.OK;
        try {
            result = Analyzer.extractTableNamesFromStatement(sql)
        } catch (e: SqlException) {
            error = e.message
            status = HttpStatus.BAD_REQUEST;
        } catch (e: Exception) {
            error = e.message
            status = HttpStatus.INTERNAL_SERVER_ERROR;
        }
        return HttpResponse
                .status<Map<String, Any?>>(status)
                .body(mapOf(
                        Pair("result", result),
                        Pair("error", error)))
    }

    @Post(uri = "/format-sql", consumes =[MediaType.TEXT_PLAIN], produces = [MediaType.APPLICATION_JSON])
    fun formatSQL(@Body sql: String): HttpResponse<Map<String, Any?>> {
        var result: String? = null
        var error: String? = null
        var status = HttpStatus.OK;
        try {
            result = formatter.formatSql(sql)
        } catch (e: SqlException) {
            status = HttpStatus.BAD_REQUEST;
        } catch (e: Exception) {
            error = e.message
            status = HttpStatus.INTERNAL_SERVER_ERROR;
        }
        return HttpResponse
                .status<Map<String, Any?>>(status)
                .body(mapOf(
                        Pair("result", result),
                        Pair("error", error)))
    }
}

object Application {
    @JvmStatic
    fun main(args: Array<String>) {
        Micronaut.run(Application.javaClass)
    }

}
hidarapaneni commented 4 years ago

thanks @MartinSahlen i tried both on macos and linux.. not sure what the issue is. will see if there are any lib conflicts..

MartinSahlen commented 4 years ago

@hidarapaneni Yes I'm sorry I've not been able to be more helpful. It could be a dreaded classpath issue as you say - inspecting the dependency tree and / or deleting the mvn/gradle cache might be worth trying. Hope you figure it out.

laughedelic commented 4 years ago

@hidarapaneni Check that you have .../META-INF/services/com.google.zetasql.ClientChannelProvider file on your classpath. It is used by the ServiceLoader to discover the JniChannelProvider.

roostapour commented 4 years ago

@hidarapaneni where you able to solve your problem? I am getting the same error java.lang.IllegalStateException: No ZetaSQL ClientChannelProvider loaded. and don't know how to solve it.

roostapour commented 4 years ago

@MartinSahlen @hidarapaneni Any idea how I can solve this issue? I also opened it as a separate issue here https://github.com/google/zetasql/issues/46

roostapour commented 4 years ago

My problem was having both zetasql-jni-channel and zetasql-client in the pom.xml. Mentioned in details here https://github.com/google/zetasql/issues/46.

egal-dev commented 3 years ago

Hi @MartinSahlen, tried to run your java example and I'm getting this error in runtime. Any idea why that happens? I have zetasql-client and zetasql-jni-channel in pom.xml, also no success with just zetasql-jni-channel as @roostapour mentioned. Trying to run it on virtualbox VM Ubuntu 20.10

Update: Tried also on on 18.04 - same result

MartinSahlen commented 3 years ago

Hi @egal-dev, sorry for the late response here. I'm not actively using ZetaSQL anymore, so there are probaly others that could help out more. A few thoughts - 1) my example code could be outdated as of now 2) If not, my bet is that, like most others here there are some dependency resolution issues.

EDIT 03.03.2021: To be more specfic, you're not mentioning how it is being run - from an IDE like intellij, from a fat jar, or from a jar with classpaths added. Most likely your issue resides somewhere here but it is unlikely an issue with ZetaSQL itself.

masterlittle commented 2 years ago

@unusualmutant Hey, do you still have the code by any chance? Or can you help with 2 things?

unusualmutant commented 2 years ago

@unusualmutant Hey, do you still have the code by any chance? Or can you help with 2 things?

  • I am unable to get the alias to actual column mapping in the WITH clause. This precents me from getting a complete column lineage for. output columns.
  • Have you registered custom UDF in the catalog? Not sure how to create a Function from actual Bigquery routines.

Hi @masterlittle , I haven't worked with it for a year now and can't really remember much :D, but I can send you the latest version of our code on that project, and maybe you can find something that helps you? Give me your email and I'll send you a link.

masterlittle commented 2 years ago

@unusualmutant Hey, do you still have the code by any chance? Or can you help with 2 things?

  • I am unable to get the alias to actual column mapping in the WITH clause. This precents me from getting a complete column lineage for. output columns.
  • Have you registered custom UDF in the catalog? Not sure how to create a Function from actual Bigquery routines.

Hi @masterlittle , I haven't worked with it for a year now and can't really remember much :D, but I can send you the latest version of our code on that project, and maybe you can find something that helps you? Give me your email and I'll send you a link.

Hahaha. Sure. Every bit helps. Here's my ID - goyalshitij@gmail.com

unusualmutant commented 2 years ago

Sent :)

On Tue, 11 Jan 2022 at 12:21, Shitij Goyal @.***> wrote:

@unusualmutant https://github.com/unusualmutant Hey, do you still have the code by any chance? Or can you help with 2 things?

  • I am unable to get the alias to actual column mapping in the WITH clause. This precents me from getting a complete column lineage for. output columns.
  • Have you registered custom UDF in the catalog? Not sure how to create a Function from actual Bigquery routines.

Hi @masterlittle https://github.com/masterlittle , I haven't worked with it for a year now and can't really remember much :D, but I can send you the latest version of our code on that project, and maybe you can find something that helps you? Give me your email and I'll send you a link.

Hahaha. Sure. Every bit helps. Here's my ID - @.***

— Reply to this email directly, view it on GitHub https://github.com/google/zetasql/issues/4#issuecomment-1009865333, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMEL5RF4KD65T6TG5U75CXDUVQHCBANCNFSM4HPX2SKA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

sridhar562345 commented 2 years ago

@unusualmutant @masterlittle can I have the code too?

Here's my email ID: sridhar562345@gmail.com