diff --git a/language/sql/extractor/BUILD b/language/sql/extractor/BUILD deleted file mode 100644 index 427caba2..00000000 --- a/language/sql/extractor/BUILD +++ /dev/null @@ -1,100 +0,0 @@ -load("//:junit5.bzl", "java_junit5_test") - -# add lombok annotation processor -java_import( - name = "lombok_jar", - jars = [ - "@maven//:v1/http/mvn.dev.alipay.net/artifactory/content/groups/public/org/projectlombok/lombok/1.18.16/lombok-1.18.16.jar", - ], -) - -java_plugin( - name = "lombok_processor", - # should be specified - processor_class = "lombok.launch.AnnotationProcessorHider$AnnotationProcessor", - deps = [ - ":lombok_jar", - ], -) - -# add picocli annotation processor -java_import( - name = "picocli_jar", - jars = [ - "@maven//:v1/http/mvn.dev.alipay.net/artifactory/content/groups/public/info/picocli/picocli/4.6.1/picocli-4.6.1.jar", - "@maven//:v1/http/mvn.dev.alipay.net/artifactory/content/groups/public/info/picocli/picocli-codegen/4.6.1/picocli-codegen-4.6.1.jar", - ], -) - -java_plugin( - name = "picocli_processor", - processor_class = "picocli.codegen.aot.graalvm.processor.NativeImageConfigGeneratorProcessor", - # processor_class = "picocli.codegen.aot.graalvm.processor.AbstractCompositeGeneratorProcessor", - deps = [ - ":picocli_jar", - ], -) - -# all in one exported processors library -java_library( - name = "all_processors", - exported_plugins = [ - ":lombok_processor", - ":picocli_processor", - ], - tags = ["maven:compile_only"], - exports = [ - "@maven//:info_picocli_picocli_codegen", - "@maven//:org_projectlombok_lombok", - ], -) - -java_library( - name = "util", - srcs = glob(["src/main/java/com/alipay/codequery/util/*.java"]), - deps = [ - "@maven//:org_apache_commons_commons_lang3", - "@maven//:org_apache_logging_log4j_log4j_api", - "@maven//:org_apache_logging_log4j_log4j_core", - "@maven//:org_apache_logging_log4j_log4j_slf4j_impl", - "@maven//:org_jetbrains_annotations", - "@maven//:org_slf4j_slf4j_api", - ], -) - -java_binary( - name = "coref-sql-src-extractor", - srcs = glob(["src/main/java/**/*.java"]), - main_class = "com.alipay.codequery.coref.sql.Extractor", - resources = glob(["src/main/resources/**/*"]), - visibility = ["//visibility:public"], - deps = [ - ":all_processors", - ":util", - "@maven//:com_alibaba_druid", - "@maven//:com_google_code_gson_gson", - "@maven//:com_google_guava_guava", - "@maven//:com_google_re2j_re2j", - "@maven//:com_ibm_icu_icu4j", - "@maven//:commons_codec_commons_codec", - "@maven//:commons_io_commons_io", - "@maven//:info_picocli_picocli", - "@maven//:javax_annotation_javax_annotation_api", - "@maven//:me_tongfei_progressbar", - "@maven//:net_java_dev_jna_jna", - "@maven//:org_apache_commons_commons_lang3", - "@maven//:org_apache_logging_log4j_log4j_api", - "@maven//:org_apache_logging_log4j_log4j_core", - "@maven//:org_apache_logging_log4j_log4j_slf4j_impl", - "@maven//:org_hamcrest_hamcrest_all", - "@maven//:org_ini4j_ini4j", - "@maven//:org_jetbrains_annotations", - "@maven//:org_mybatis_dynamic_sql_mybatis_dynamic_sql", - "@maven//:org_mybatis_mybatis", - "@maven//:org_projectlombok_lombok", - "@maven//:org_slf4j_slf4j_api", - "@maven//:org_xerial_sqlite_jdbc", - "@maven//:tk_mybatis_mapper", - "@maven//:uk_com_robust_it_cloning", - ], -) diff --git a/language/sql/extractor/README.md b/language/sql/extractor/README.md index 2ea1cab5..8d0cb135 100644 --- a/language/sql/extractor/README.md +++ b/language/sql/extractor/README.md @@ -24,6 +24,7 @@ Therefore, the development process requires modifying the relevant jinja2 templa # The output path must be language/sql/extractor/utils/code_generator/FindDruidSqlAstAllPublicGetterMethods.json, as step 2 will use this location by default sparrow query run /language/sql/extractor/utils/code_generator/FindDruidSqlAstAllPublicGetterMethods.gdl -f json -o /language/sql/extractor/utils/code_generator -d /db ``` + TODO: `FindDruidSqlAstAllPublicGetterMethods.gdl` is missing, to be added. 2. Generate the SQL Extractor's code based on the extracted Druid AST information. ```bash @@ -45,4 +46,6 @@ sparrow database create -lang java -s . ./db sparrow query run /language/sql/extractor/utils/druid_sql_ast_nodes/FindDruidSqlAstNodes.gdl -f json -o /language/sql/extractor/utils/druid_sql_ast_nodes -d ./db # Analyze the Sparrow output data and generate a class diagram in Dot format python3 /language/sql/extractor/utils/druid_sql_ast_nodes/generate_dot_diagram.py -``` \ No newline at end of file +``` + +TODO: `FindDruidSqlAstNodes.gdl` is missing, to be added. diff --git a/language/sql/extractor/README_cn.md b/language/sql/extractor/README_cn.md index ea177e01..4b7a768c 100644 --- a/language/sql/extractor/README_cn.md +++ b/language/sql/extractor/README_cn.md @@ -22,6 +22,7 @@ CodeFuse-Query SQL 提取器将 SQL 文件的源代码转换为标准化的 core # 输出路径必须为 language/sql/extractor/utils/code_generator/FindDruidSqlAstAllPublicGetterMethods.json,步骤2会默认使用该位置 sparrow query run /language/sql/extractor/utils/code_generator/FindDruidSqlAstAllPublicGetterMethods.gdl -f json -o /language/sql/extractor/utils/code_generator -d /db ``` + TODO: `FindDruidSqlAstAllPublicGetterMethods.gdl` 已缺失,待补充。 2. 按提取的Druid AST信息生成SQL抽取器的代码。 ```bash @@ -43,3 +44,5 @@ sparrow query run /language/sql/extractor/utils/druid_ # 分析Sparrow输出数据并生成Dot格式的类图 python3 /language/sql/extractor/utils/druid_sql_ast_nodes/generate_dot_diagram.py ``` + +TODO: `FindDruidSqlAstNodes.gdl` 已缺失,待补充。 diff --git a/language/sql/extractor/utils/code_generator/FindDruidSqlAstAllPublicGetterMethods.gdl b/language/sql/extractor/utils/code_generator/FindDruidSqlAstAllPublicGetterMethods.gdl deleted file mode 100644 index 7bab508b..00000000 --- a/language/sql/extractor/utils/code_generator/FindDruidSqlAstAllPublicGetterMethods.gdl +++ /dev/null @@ -1,180 +0,0 @@ -import coref.java.* - -predicate isNestedClass(Class c) { - exists(NestedClass n) { c = n} -} - -predicate isAbstractClass(Class c) { - c.getModifier().getName() = "abstract" -} - -predicate isStaticMethod(Method m) { - m.getModifier().getName() = "static" -} - -predicate hasParameter(Method m) { - exists(Method m, Parameter p) { - p = m.getParameter() - } -} - -predicate isDeprecated(Method m) { - exists(Method m, Annotation a, string annotationName) { - a = m.getAnnotation() - and - annotationName = a.getName() - and - contains("Deprecated", annotationName) - } -} - -class DruidSqlAstClass extends Class { - DruidSqlAstClass() { - exists(Class c, string pkg, int i, Class ancestorClass, int i) { - // Filter out nested classes - not isNestedClass(c) - and - // // Filter out abstract classes - // not isAbstractClass(c) - // and - // Should extend from SQLObjectImpl - ancestorClass = c.getAnAncestorClass() and ancestorClass.getQualifiedName() = "com.alibaba.druid.sql.ast.SQLObjectImpl" - and - this = c - and - pkg = c.getPackage().getPackageName() - and - contains("com.alibaba.druid.sql", pkg) - and - ( - contains(".ast", pkg) - or - // Special case: to include AST nodes in com.alibaba.druid.sql.dialect.hive.stmt - contains(".stmt", pkg) - ) - } - } - - Method getAllPublicGetterMethods() { - return m: exists(Method m, string methodName) { - m = this.getAllMethods() - and - // Should not be static - not isStaticMethod(m) - and - // Should have no parameter - not hasParameter(m) - and - // Should not be deprecated - not isDeprecated(m) - and - methodName = m.getName() - and - ( - match("^get.*", methodName) - or - match("^is.*", methodName) - ) - and - m.getModifier().getName() = "public" - } - } -} - -@inline -predicate ifIsAbstract(Class c, int isAbstract) { - if(isAbstractClass(c)) - then( - isAbstract = 1 - ) - else( - isAbstract = 0 - ) -} - -predicate typeOfAstClass(Type t) { - exists(DruidSqlAstClass c, ReferenceType rt) { - ( - (rt = t and c.getQualifiedName() = rt.getQualifiedName()) - or - (t = c) - ) - } -} - -@inline -predicate ifIsAnAstClass(Type t, int isAnAstClass) { - if(typeOfAstClass(t)) - then( - isAnAstClass = 1 - ) - else( - isAnAstClass = 0 - ) -} - -predicate getImplementsInterface(DruidSqlAstClass c) { - exists(Interface i) { - i = c.getImplementsInterface() - } -} - -predicate getImplementsInterfaceName(DruidSqlAstClass c, string implementsInterfaceName) { - exists(DruidSqlAstClass x) { - x = c - and - if(getImplementsInterface(x)) - then( - exists(Interface i) { - i = x.getImplementsInterface() - and - implementsInterfaceName = i.getName() - } - ) - else( - implementsInterfaceName = "" - ) - } -} - -predicate output(string qualifiedName, string className, string methodName, string returnTypeName, int isReturnTypeAnAstClass, int isAbstract, string superClassName, string implementsInterfaceName) { - exists(DruidSqlAstClass c, Class superClass, Type returnType, Class returnedClass) { - qualifiedName = c.getQualifiedName() - and - className = c.getName() - and - superClass = c.getSuperClass() - and - ifIsAbstract(c, isAbstract) - and - superClassName = superClass.getQualifiedName() - and - getImplementsInterfaceName(c, implementsInterfaceName) - and - if(count{ - exists(Method m) { - m = c.getAllPublicGetterMethods() - } - } > 0) - then( - exists(Method m) { - m = c.getAllPublicGetterMethods() - and - methodName = m.getName() - and - returnType = m.getType() - and - returnTypeName = returnType.getName() - and - ifIsAnAstClass(returnType, isReturnTypeAnAstClass) - } - ) - else( - methodName = "" - and - returnTypeName = "" - and - isReturnTypeAnAstClass = 0 - ) - } -} diff --git a/language/sql/extractor/utils/druid_sql_ast_nodes/FindDruidSqlAstNodes.gdl b/language/sql/extractor/utils/druid_sql_ast_nodes/FindDruidSqlAstNodes.gdl deleted file mode 100644 index 402a2b7d..00000000 --- a/language/sql/extractor/utils/druid_sql_ast_nodes/FindDruidSqlAstNodes.gdl +++ /dev/null @@ -1,19 +0,0 @@ -import coref.java.* - -predicate output(string className, string superClassName) { - exists(Class c, string pkg) { - className = c.getName() - and - pkg = c.getPackage().getPackageName() - and - contains("com.alibaba.druid.sql", pkg) - and - ( - contains(".ast", pkg) - or - // Special case: to include AST nodes in com.alibaba.druid.sql.dialect.hive.stmt - contains(".stmt", pkg)) - and - superClassName = c.getSuperClass().getName() - } -} \ No newline at end of file