mirror of
https://github.com/BillyOutlast/posthog.git
synced 2026-02-04 03:01:23 +01:00
chore(devex): common hogql_parser (#27719)
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
4
.github/actions/run-backend-tests/action.yml
vendored
4
.github/actions/run-backend-tests/action.yml
vendored
@@ -63,7 +63,7 @@ runs:
|
||||
id: hogql-parser-diff
|
||||
run: |
|
||||
git fetch --no-tags --prune --depth=1 origin master
|
||||
changed=$(git diff --quiet HEAD origin/master -- hogql_parser/ && echo "false" || echo "true")
|
||||
changed=$(git diff --quiet HEAD origin/master -- common/hogql_parser/ && echo "false" || echo "true")
|
||||
echo "changed=$changed" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Install SAML (python3-saml) dependencies
|
||||
@@ -122,7 +122,7 @@ runs:
|
||||
sudo cp out/usr/local/lib/libantlr4-runtime.so* /usr/lib/
|
||||
sudo ldconfig
|
||||
cd ..
|
||||
uv pip install --system ./hogql_parser
|
||||
uv pip install --system ./common/hogql_parser
|
||||
|
||||
- name: Set up needed files
|
||||
shell: bash
|
||||
|
||||
18
.github/workflows/build-hogql-parser.yml
vendored
18
.github/workflows/build-hogql-parser.yml
vendored
@@ -3,7 +3,7 @@ name: Release hogql-parser
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- hogql_parser/**
|
||||
- common/hogql_parser/**
|
||||
- .github/workflows/build-hogql-parser.yml
|
||||
|
||||
concurrency:
|
||||
@@ -21,14 +21,14 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 0 # Fetching all for comparison since last push (not just last commit)
|
||||
|
||||
- name: Check if hogql_parser/ has changed
|
||||
- name: Check if common/hogql_parser/ has changed
|
||||
id: changed-files
|
||||
uses: tj-actions/changed-files@v43
|
||||
with:
|
||||
since_last_remote_commit: true
|
||||
files_yaml: |
|
||||
parser:
|
||||
- hogql_parser/**
|
||||
- common/hogql_parser/**
|
||||
|
||||
- name: Check if version was bumped
|
||||
shell: bash
|
||||
@@ -37,7 +37,7 @@ jobs:
|
||||
parser_release_needed='false'
|
||||
if [[ ${{ steps.changed-files.outputs.parser_any_changed }} == 'true' ]]; then
|
||||
published=$(curl -fSsl https://pypi.org/pypi/hogql-parser/json | jq -r '.info.version')
|
||||
local=$(python hogql_parser/setup.py --version)
|
||||
local=$(python common/hogql_parser/setup.py --version)
|
||||
if [[ "$published" != "$local" ]]; then
|
||||
parser_release_needed='true'
|
||||
else
|
||||
@@ -86,13 +86,13 @@ jobs:
|
||||
|
||||
- name: Build sdist
|
||||
if: matrix.os == 'ubuntu-22.04' # Only build the sdist once
|
||||
run: cd hogql_parser && python setup.py sdist
|
||||
run: cd common/hogql_parser && python setup.py sdist
|
||||
|
||||
- name: Install cibuildwheel
|
||||
run: pip install cibuildwheel==2.16.*
|
||||
|
||||
- name: Build wheels
|
||||
run: cd hogql_parser && python -m cibuildwheel --output-dir dist
|
||||
run: cd common/hogql_parser && python -m cibuildwheel --output-dir dist
|
||||
env:
|
||||
MACOSX_DEPLOYMENT_TARGET: '13' # A modern target allows us to use C++20
|
||||
|
||||
@@ -101,8 +101,8 @@ jobs:
|
||||
with:
|
||||
name: wheels-${{ matrix.os }}
|
||||
path: |
|
||||
hogql_parser/dist/*.whl
|
||||
hogql_parser/dist/*.tar.gz
|
||||
common/hogql_parser/dist/*.whl
|
||||
common/hogql_parser/dist/*.tar.gz
|
||||
if-no-files-found: error
|
||||
|
||||
publish:
|
||||
@@ -142,7 +142,7 @@ jobs:
|
||||
- name: Update hogql-parser in requirements
|
||||
shell: bash
|
||||
run: |
|
||||
local=$(python hogql_parser/setup.py --version)
|
||||
local=$(python common/hogql_parser/setup.py --version)
|
||||
sed -i "s/hogql-parser==.*/hogql-parser==${local}/g" requirements.in
|
||||
sed -i "s/hogql-parser==.*/hogql-parser==${local}/g" requirements.txt
|
||||
|
||||
|
||||
2
.github/workflows/ci-hog.yml
vendored
2
.github/workflows/ci-hog.yml
vendored
@@ -111,7 +111,7 @@ jobs:
|
||||
npm run grammar:build && git diff --exit-code
|
||||
env:
|
||||
# Installing a version of ANTLR compatible with what's in Homebrew as of August 2024 (version 4.13.2),
|
||||
# as apt-get is quite out of date. The same version must be set in hogql_parser/pyproject.toml
|
||||
# as apt-get is quite out of date. The same version must be set in common/hogql_parser/pyproject.toml
|
||||
ANTLR_VERSION: '4.13.2'
|
||||
|
||||
- name: Check if STL bytecode is up to date
|
||||
|
||||
@@ -55,7 +55,7 @@ The three pages below are must-reads though. They're key to writing production-r
|
||||
1. Install `hogql_parser` by building from local sources:
|
||||
|
||||
```bash
|
||||
pip install ./hogql_parser
|
||||
pip install ./common/hogql_parser
|
||||
```
|
||||
|
||||
> If you're getting compilation errors like this on macOS Sonoma:
|
||||
@@ -32,7 +32,7 @@ module = Extension(
|
||||
|
||||
setup(
|
||||
name="hogql_parser",
|
||||
version="1.0.49",
|
||||
version="1.0.50",
|
||||
url="https://github.com/PostHog/posthog/tree/master/hogql_parser",
|
||||
author="PostHog Inc.",
|
||||
author_email="hey@posthog.com",
|
||||
@@ -282,7 +282,8 @@ export function exec(input: any[] | VMState | Bytecodes, options?: ExecOptions):
|
||||
if (!options?.external?.regex?.match) {
|
||||
throw new HogVMException('Set options.external.regex.match for RegEx support')
|
||||
}
|
||||
return (regex: string, value: string): boolean => regex && value ? !!options.external?.regex?.match(regex, value) : false
|
||||
return (regex: string, value: string): boolean =>
|
||||
regex && value ? !!options.external?.regex?.match(regex, value) : false
|
||||
}
|
||||
|
||||
const logTelemetry = (): void => {
|
||||
@@ -306,7 +307,7 @@ export function exec(input: any[] | VMState | Bytecodes, options?: ExecOptions):
|
||||
frame.ip,
|
||||
typeof chunkBytecode[frame.ip] === 'number'
|
||||
? String(chunkBytecode[frame.ip]) +
|
||||
(operations[chunkBytecode[frame.ip]] ? `/${operations[chunkBytecode[frame.ip]]}` : '')
|
||||
(operations[chunkBytecode[frame.ip]] ? `/${operations[chunkBytecode[frame.ip]]}` : '')
|
||||
: '???',
|
||||
debug,
|
||||
])
|
||||
@@ -316,18 +317,18 @@ export function exec(input: any[] | VMState | Bytecodes, options?: ExecOptions):
|
||||
|
||||
const nextOp = options?.telemetry
|
||||
? () => {
|
||||
ops += 1
|
||||
logTelemetry()
|
||||
if ((ops & 31) === 0) {
|
||||
checkTimeout()
|
||||
}
|
||||
}
|
||||
ops += 1
|
||||
logTelemetry()
|
||||
if ((ops & 31) === 0) {
|
||||
checkTimeout()
|
||||
}
|
||||
}
|
||||
: () => {
|
||||
ops += 1
|
||||
if ((ops & 31) === 0) {
|
||||
checkTimeout()
|
||||
}
|
||||
}
|
||||
ops += 1
|
||||
if ((ops & 31) === 0) {
|
||||
checkTimeout()
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
while (true) {
|
||||
@@ -595,7 +596,7 @@ export function exec(input: any[] | VMState | Bytecodes, options?: ExecOptions):
|
||||
case Operation.TUPLE:
|
||||
temp = next()
|
||||
tempArray = spliceStack2(stack.length - temp, temp)
|
||||
; (tempArray as any).__isHogTuple = true
|
||||
;(tempArray as any).__isHogTuple = true
|
||||
pushStack(tempArray)
|
||||
break
|
||||
case Operation.JUMP:
|
||||
@@ -738,8 +739,8 @@ export function exec(input: any[] | VMState | Bytecodes, options?: ExecOptions):
|
||||
const args =
|
||||
version === 0
|
||||
? Array(temp)
|
||||
.fill(null)
|
||||
.map(() => popStack())
|
||||
.fill(null)
|
||||
.map(() => popStack())
|
||||
: stackKeepFirstElements(stack.length - temp)
|
||||
if (args.length !== 1) {
|
||||
throw new HogVMException(`Function ${name} requires exactly 1 argument`)
|
||||
@@ -771,8 +772,8 @@ export function exec(input: any[] | VMState | Bytecodes, options?: ExecOptions):
|
||||
const args =
|
||||
version === 0
|
||||
? Array(temp)
|
||||
.fill(null)
|
||||
.map(() => popStack())
|
||||
.fill(null)
|
||||
.map(() => popStack())
|
||||
: stackKeepFirstElements(stack.length - temp)
|
||||
pushStack(convertJSToHog(options.functions[name](...args.map((v) => convertHogToJS(v)))))
|
||||
} else if (
|
||||
@@ -789,8 +790,8 @@ export function exec(input: any[] | VMState | Bytecodes, options?: ExecOptions):
|
||||
const args =
|
||||
version === 0
|
||||
? Array(temp)
|
||||
.fill(null)
|
||||
.map(() => popStack())
|
||||
.fill(null)
|
||||
.map(() => popStack())
|
||||
: stackKeepFirstElements(stack.length - temp)
|
||||
|
||||
frame.ip += 1 // resume at the next address after async returns
|
||||
@@ -809,8 +810,8 @@ export function exec(input: any[] | VMState | Bytecodes, options?: ExecOptions):
|
||||
const args =
|
||||
version === 0
|
||||
? Array(temp)
|
||||
.fill(null)
|
||||
.map(() => popStack())
|
||||
.fill(null)
|
||||
.map(() => popStack())
|
||||
: stackKeepFirstElements(stack.length - temp)
|
||||
pushStack(STL[name].fn(args, name, options))
|
||||
} else if (name in BYTECODE_STL) {
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { ExecOptions } from '../types'
|
||||
|
||||
export function sha256Hex(data: string | null, options?: ExecOptions): string | null {
|
||||
if (data === null) { return null }
|
||||
if (data === null) {
|
||||
return null
|
||||
}
|
||||
const crypto = options?.external?.crypto
|
||||
if (!crypto) {
|
||||
throw new Error('The crypto module is required for "sha256Hex" to work.')
|
||||
@@ -10,7 +12,9 @@ export function sha256Hex(data: string | null, options?: ExecOptions): string |
|
||||
}
|
||||
|
||||
export function md5Hex(data: string | null, options?: ExecOptions): string | null {
|
||||
if (data === null) { return null }
|
||||
if (data === null) {
|
||||
return null
|
||||
}
|
||||
const crypto = options?.external?.crypto
|
||||
if (!crypto) {
|
||||
throw new Error('The crypto module is required for "md5Hex" to work.')
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
"schema:build:python": "bash bin/build-schema-python.sh",
|
||||
"grammar:build": "npm run grammar:build:python && npm run grammar:build:cpp",
|
||||
"grammar:build:python": "cd posthog/hogql/grammar && antlr -Dlanguage=Python3 HogQLLexer.g4 && antlr -visitor -no-listener -Dlanguage=Python3 HogQLParser.g4",
|
||||
"grammar:build:cpp": "cd posthog/hogql/grammar && antlr -o ../../../hogql_parser -Dlanguage=Cpp HogQLLexer.g4 && antlr -o ../../../hogql_parser -visitor -no-listener -Dlanguage=Cpp HogQLParser.g4",
|
||||
"grammar:build:cpp": "cd posthog/hogql/grammar && antlr -o ../../../common/hogql_parser -Dlanguage=Cpp HogQLLexer.g4 && antlr -o ../../../common/hogql_parser -visitor -no-listener -Dlanguage=Cpp HogQLParser.g4",
|
||||
"packages:build": "pnpm packages:build:lemon-ui",
|
||||
"packages:build:lemon-ui": "cd frontend/@posthog/lemon-ui && pnpm i && pnpm build",
|
||||
"editor:update-tsd": "pnpm packages:build && node frontend/editor-update-tsd.mjs",
|
||||
|
||||
@@ -23,7 +23,7 @@ depends_on = [
|
||||
]
|
||||
|
||||
[[modules]]
|
||||
path = "hogql_parser"
|
||||
path = "common.hogql_parser"
|
||||
depends_on = []
|
||||
|
||||
[[modules]]
|
||||
@@ -37,7 +37,7 @@ path = "posthog"
|
||||
depends_on = [
|
||||
"<root>",
|
||||
"ee",
|
||||
"hogql_parser",
|
||||
"common.hogql_parser",
|
||||
"common.hogvm.python",
|
||||
"products.early_access_features",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user