0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-24 09:14:46 +01:00

fix(hog): bools and numbers are not "empty" (#24835)

This commit is contained in:
Marius Andra 2024-09-06 11:12:41 +02:00 committed by GitHub
parent b3d24c3dec
commit 7b71abc8d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 49 additions and 30 deletions

View File

@ -14,13 +14,14 @@
"print", 1, 35, 32, "string", 2, "empty", 1, 2, "print", 1, 35, 32, "0", 2, "empty", 1, 2, "print", 1, 35, 43, 0, 2,
"empty", 1, 2, "print", 1, 35, 42, 0, 2, "empty", 1, 2, "print", 1, 35, 2, "tuple", 0, 2, "empty", 1, 2, "print", 1, 35,
33, 0, 2, "tuple", 1, 2, "empty", 1, 2, "print", 1, 35, 33, 1, 33, 2, 2, "tuple", 2, 2, "empty", 1, 2, "print", 1, 35,
32, "", 2, "print", 1, 35, 32, "-- notEmpty --", 2, "print", 1, 35, 31, 2, "notEmpty", 1, 2, "print", 1, 35, 33, 0, 2,
"notEmpty", 1, 2, "print", 1, 35, 33, 1, 2, "notEmpty", 1, 2, "print", 1, 35, 33, -1, 2, "notEmpty", 1, 2, "print", 1,
35, 34, 0.0, 2, "notEmpty", 1, 2, "print", 1, 35, 34, 0.01, 2, "notEmpty", 1, 2, "print", 1, 35, 32, "", 2, "notEmpty",
1, 2, "print", 1, 35, 32, "string", 2, "notEmpty", 1, 2, "print", 1, 35, 32, "0", 2, "notEmpty", 1, 2, "print", 1, 35,
43, 0, 2, "notEmpty", 1, 2, "print", 1, 35, 42, 0, 2, "notEmpty", 1, 2, "print", 1, 35, 2, "tuple", 0, 2, "notEmpty", 1,
2, "print", 1, 35, 33, 0, 2, "tuple", 1, 2, "notEmpty", 1, 2, "print", 1, 35, 33, 1, 33, 2, 2, "tuple", 2, 2,
"notEmpty", 1, 2, "print", 1, 35, 32, "", 2, "print", 1, 35, 32, "-- replaceAll, replaceOne --", 2, "print", 1, 35, 32,
"hello world", 32, "l", 32, "L", 2, "replaceAll", 3, 2, "print", 1, 35, 32, "hello world", 32, "l", 32, "L", 2,
"replaceOne", 3, 2, "print", 1, 35, 32, "", 2, "print", 1, 35, 32, "-- generateUUIDv4 --", 2, "print", 1, 35, 2,
"generateUUIDv4", 0, 2, "length", 1, 2, "print", 1, 35]
29, 2, "empty", 1, 2, "print", 1, 35, 30, 2, "empty", 1, 2, "print", 1, 35, 32, "", 2, "print", 1, 35, 32,
"-- notEmpty --", 2, "print", 1, 35, 31, 2, "notEmpty", 1, 2, "print", 1, 35, 33, 0, 2, "notEmpty", 1, 2, "print", 1,
35, 33, 1, 2, "notEmpty", 1, 2, "print", 1, 35, 33, -1, 2, "notEmpty", 1, 2, "print", 1, 35, 34, 0.0, 2, "notEmpty", 1,
2, "print", 1, 35, 34, 0.01, 2, "notEmpty", 1, 2, "print", 1, 35, 32, "", 2, "notEmpty", 1, 2, "print", 1, 35, 32,
"string", 2, "notEmpty", 1, 2, "print", 1, 35, 32, "0", 2, "notEmpty", 1, 2, "print", 1, 35, 43, 0, 2, "notEmpty", 1, 2,
"print", 1, 35, 42, 0, 2, "notEmpty", 1, 2, "print", 1, 35, 2, "tuple", 0, 2, "notEmpty", 1, 2, "print", 1, 35, 33, 0,
2, "tuple", 1, 2, "notEmpty", 1, 2, "print", 1, 35, 33, 1, 33, 2, 2, "tuple", 2, 2, "notEmpty", 1, 2, "print", 1, 35,
29, 2, "notEmpty", 1, 2, "print", 1, 35, 30, 2, "notEmpty", 1, 2, "print", 1, 35, 32, "", 2, "print", 1, 35, 32,
"-- replaceAll, replaceOne --", 2, "print", 1, 35, 32, "hello world", 32, "l", 32, "L", 2, "replaceAll", 3, 2, "print",
1, 35, 32, "hello world", 32, "l", 32, "L", 2, "replaceOne", 3, 2, "print", 1, 35, 32, "", 2, "print", 1, 35, 32,
"-- generateUUIDv4 --", 2, "print", 1, 35, 2, "generateUUIDv4", 0, 2, "length", 1, 2, "print", 1, 35]

View File

@ -17,10 +17,10 @@ tom & jerry
-- empty --
true
true
false
false
true
false
false
false
true
false
@ -30,13 +30,15 @@ true
true
false
false
false
false
-- notEmpty --
false
false
true
true
false
true
true
true
false
true
@ -46,6 +48,8 @@ false
false
true
true
true
true
-- replaceAll, replaceOne --
heLLo worLd

View File

@ -30,6 +30,8 @@ print(empty({}))
print(empty(tuple()))
print(empty(tuple(0)))
print(empty(tuple(1,2)))
print(empty(true))
print(empty(false))
print('')
print('-- notEmpty --')
print(notEmpty(null))
@ -46,6 +48,8 @@ print(notEmpty({}))
print(notEmpty(tuple()))
print(notEmpty(tuple(0)))
print(notEmpty(tuple(1,2)))
print(notEmpty(true))
print(notEmpty(false))
print('')
print('-- replaceAll, replaceOne --')
print(replaceAll('hello world', 'l', 'L'))

View File

@ -100,6 +100,12 @@ def ifNull(args: list[Any], team: Optional["Team"], stdout: Optional[list[str]],
return args[1]
def empty(args: list[Any], team: Optional["Team"], stdout: Optional[list[str]], timeout: float):
if isinstance(args[0], bool) or isinstance(args[0], int) or isinstance(args[0], float):
return False
return not bool(args[0])
def sleep(args: list[Any], team: Optional["Team"], stdout: Optional[list[str]], timeout: float):
time.sleep(args[0])
return None
@ -367,8 +373,10 @@ STL: dict[str, STLFunction] = {
"toFloat": STLFunction(fn=toFloat, minArgs=1, maxArgs=1),
"ifNull": STLFunction(fn=ifNull, minArgs=2, maxArgs=2),
"length": STLFunction(fn=lambda args, team, stdout, timeout: len(args[0]), minArgs=1, maxArgs=1),
"empty": STLFunction(fn=lambda args, team, stdout, timeout: not bool(args[0]), minArgs=1, maxArgs=1),
"notEmpty": STLFunction(fn=lambda args, team, stdout, timeout: bool(args[0]), minArgs=1, maxArgs=1),
"empty": STLFunction(fn=empty, minArgs=1, maxArgs=1),
"notEmpty": STLFunction(
fn=lambda args, team, stdout, timeout: not empty(args, team, stdout, timeout), minArgs=1, maxArgs=1
),
"tuple": STLFunction(fn=lambda args, team, stdout, timeout: tuple(args), minArgs=0, maxArgs=None),
"lower": STLFunction(fn=lambda args, team, stdout, timeout: args[0].lower(), minArgs=1, maxArgs=1),
"upper": STLFunction(fn=lambda args, team, stdout, timeout: args[0].upper(), minArgs=1, maxArgs=1),

View File

@ -1,6 +1,6 @@
{
"name": "@posthog/hogvm",
"version": "1.0.46",
"version": "1.0.47",
"description": "PostHog Hog Virtual Machine",
"types": "dist/index.d.ts",
"source": "src/index.ts",

View File

@ -115,6 +115,8 @@ export const STL: Record<string, STLFunction> = {
return args[0].size === 0
}
return Object.keys(args[0]).length === 0
} else if (typeof args[0] === 'number' || typeof args[0] === 'boolean') {
return false
}
return !args[0]
},

View File

@ -77,7 +77,7 @@
"@medv/finder": "^3.1.0",
"@microlink/react-json-view": "^1.21.3",
"@monaco-editor/react": "4.6.0",
"@posthog/hogvm": "^1.0.46",
"@posthog/hogvm": "^1.0.47",
"@posthog/icons": "0.8.1",
"@posthog/plugin-scaffold": "^1.4.4",
"@react-hook/size": "^2.1.2",

View File

@ -53,7 +53,7 @@
"@maxmind/geoip2-node": "^3.4.0",
"@posthog/clickhouse": "^1.7.0",
"@posthog/cyclotron": "file:../rust/cyclotron-node",
"@posthog/hogvm": "^1.0.46",
"@posthog/hogvm": "^1.0.47",
"@posthog/plugin-scaffold": "1.4.4",
"@sentry/node": "^7.49.0",
"@sentry/profiling-node": "^0.3.0",

View File

@ -47,8 +47,8 @@ dependencies:
specifier: file:../rust/cyclotron-node
version: file:../rust/cyclotron-node
'@posthog/hogvm':
specifier: ^1.0.46
version: 1.0.46(luxon@3.4.4)
specifier: ^1.0.47
version: 1.0.47(luxon@3.4.4)
'@posthog/plugin-scaffold':
specifier: 1.4.4
version: 1.4.4
@ -3116,8 +3116,8 @@ packages:
engines: {node: '>=12'}
dev: false
/@posthog/hogvm@1.0.46(luxon@3.4.4):
resolution: {integrity: sha512-oTXytxHImxcAUYvK+QVI5nRc3YnVSbn01rFlOrpeTYjW5oqYKMR8nYsjhHGLt5p0pnfeBhmQjBM5mJtVs5bA2Q==}
/@posthog/hogvm@1.0.47(luxon@3.4.4):
resolution: {integrity: sha512-6zoMKH6fmO9evuhpd9dtkVi2GFk+dGsxcHe6l6mMo7yXd0Kwssmiwr8aLndYTsjdhRkVMi7iaoi/GLrh8F9ayQ==}
peerDependencies:
luxon: ^3.4.4
dependencies:

View File

@ -53,8 +53,8 @@ dependencies:
specifier: 4.6.0
version: 4.6.0(monaco-editor@0.49.0)(react-dom@18.2.0)(react@18.2.0)
'@posthog/hogvm':
specifier: ^1.0.46
version: 1.0.46(luxon@3.5.0)
specifier: ^1.0.47
version: 1.0.47(luxon@3.5.0)
'@posthog/icons':
specifier: 0.8.1
version: 0.8.1(react-dom@18.2.0)(react@18.2.0)
@ -5414,8 +5414,8 @@ packages:
resolution: {integrity: sha512-50/17A98tWUfQ176raKiOGXuYpLyyVMkxxG6oylzL3BPOlA6ADGdK7EYunSa4I064xerltq9TGXs8HmOk5E+vw==}
dev: false
/@posthog/hogvm@1.0.46(luxon@3.5.0):
resolution: {integrity: sha512-oTXytxHImxcAUYvK+QVI5nRc3YnVSbn01rFlOrpeTYjW5oqYKMR8nYsjhHGLt5p0pnfeBhmQjBM5mJtVs5bA2Q==}
/@posthog/hogvm@1.0.47(luxon@3.5.0):
resolution: {integrity: sha512-6zoMKH6fmO9evuhpd9dtkVi2GFk+dGsxcHe6l6mMo7yXd0Kwssmiwr8aLndYTsjdhRkVMi7iaoi/GLrh8F9ayQ==}
peerDependencies:
luxon: ^3.4.4
dependencies:
@ -18298,7 +18298,7 @@ packages:
react: '>=15'
dependencies:
react: 18.2.0
unlayer-types: 1.75.0
unlayer-types: 1.77.0
dev: false
/react-error-boundary@3.1.4(react@18.2.0):
@ -20832,8 +20832,8 @@ packages:
resolution: {integrity: sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==}
engines: {node: '>= 10.0.0'}
/unlayer-types@1.75.0:
resolution: {integrity: sha512-yB4TeimlZPKkAGIIE3Acs9e5YHjCpeGcoybq/E8w4lzNTI5EybI9Z9rwIBXhNK0miNarxEIO7rJUWB+Yeve80g==}
/unlayer-types@1.77.0:
resolution: {integrity: sha512-/eIyHiGWO/EFb3GuD7FqD+jV9sXAj2FMhwn3QTVaio2FUz30RRAh8kQS+qNwPKIcLEZWKzfH41SBi3afudEVAA==}
dev: false
/unpipe@1.0.0: