<jupyter_start><jupyter_text>Running the Calcite SPARQL adapter using the jaydebeapi library<jupyter_code>!python3 -m pip install --user jaydebeapi
import jaydebeapi
import os
import jpype
# Requires to run "mvn package" on calcite-sparql-core first
jar = "../../core/target/calcite-sparql-core-0.0.1-SNAPSHOT.jar"

# The following lines are not always needed, but most of the times they are because
# the JVM is started without the needed JAR file (see for instance
# https://github.com/baztian/jaydebeapi/issues/85)
os.environ["JAVA_HOME"] = "/usr/lib/jvm/java-11-openjdk/"
os.environ["CLASSPATH"] = jar

args = "-Djava.class.path=%s" % jar
jvm_path = jpype.getDefaultJVMPath()
jpype.startJVM(jvm_path, args)
query = """
SELECT w3_label, w3_comment, w3_sameAs, xmlns_name, xmlns_homepage, xmlns_depiction
FROM Company
LIMIT 10
"""

with jaydebeapi.connect(
    "org.apache.calcite.avatica.remote.Driver",
    "jdbc:calcite:model=../java/src/main/resources/modelClassRemote.json",
    driver_args={"lex": "JAVA"},
    jars=jar
) as conn:
    with conn.cursor() as curs:
        curs.execute(query)
        print(curs.fetchone())<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1285591026747196, 'fraction_numerical': 0.011216566005176877, 'mean_word_length': 4.603864734299517, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, '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}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '147281', 'license': 'ECL-2.0', 'n_tokens_mistral': 436, 'n_tokens_neox': 428, 'n_words': 96, 'path': 'examples/python/Query DBPedia with jaydebeapi.ipynb', 'repo_name': 'nvitucci/calcite-sparql', 'size': '1159'}