<commit_before>package com.github.bedrin.jdbc.sniffer.sql;

public class Query {

    public final Type type;

    public Query(Type type) {
        this.type = type;
    }

    public enum Type {
        SELECT,
        INSERT,
        UPDATE,
        DELETE,
        MERGE,
        OTHER,
        ALL
    }

    public static Query parse(String sql) {

        if (null == sql) return null;

        String normalized = sql.trim().toLowerCase();

        Type type;

        if (normalized.startsWith("select ") || normalized.startsWith("with ")) {
            type = Type.SELECT;
        } else if (normalized.startsWith("insert ")) {
            type = Type.INSERT;
        } else if (normalized.startsWith("update ")) {
            type = Type.UPDATE;
        } else if (normalized.startsWith("delete ")) {
            type = Type.DELETE;
        } else if (normalized.startsWith("merge ")) {
            type = Type.MERGE;
        } else {
            type = Type.OTHER;
        }

        return new Query(type);<commit_msg>Do not treat "WITH ..." statements as select since they can be MERGE statements as well<commit_after>package com.github.bedrin.jdbc.sniffer.sql;

public class Query {

    public final Type type;

    public Query(Type type) {
        this.type = type;
    }

    public enum Type {
        SELECT,
        INSERT,
        UPDATE,
        DELETE,
        MERGE,
        OTHER,
        ALL
    }

    public static Query parse(String sql) {

        if (null == sql) return null;

        String normalized = sql.trim().toLowerCase();

        Type type;

        if (normalized.startsWith("select ")) {
            // TODO: can start with "WITH" statement
            type = Type.SELECT;
        } else if (normalized.startsWith("insert ")) {
            type = Type.INSERT;
        } else if (normalized.startsWith("update ")) {
            type = Type.UPDATE;
        } else if (normalized.startsWith("delete ")) {
            type = Type.DELETE;
        } else if (normalized.startsWith("merge ")) {
            // TODO: can start with "WITH" statement
            type = Type.MERGE;
        } else {
            type = Type.OTHER;
        }

        return new Query(type);
{'fraction_non_alphanumeric': 0.1105072463768116, 'fraction_numerical': 0.0, 'mean_word_length': 1.6971916971916972, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6270060', 'n_tokens_mistral': 638, 'n_tokens_neox': 612, 'n_words': 164}