Skip to content

Commit 8dc9f5b

Browse files
authored
Merge pull request Automattic#33 from Automattic/upgrade/thrift-libs
ThriftSQL v0.3.0 - Added - Ability to send Impala queries with usernames - Added - Default usernames to help limit invalid configurations - Added - Automatically closing query handles after all results are read - Added - Canceling queries on the server when timeouts are reached - Upgraded - Libraries to `Thrift@0.12.0`, `Hive@1.1.0`, `Impala@2.12.0` - Improved - Switched to a different classmap generator to get rid of a needless monkey patch of Beeswax service interface - Improved - Better wrapping of underlying exceptions to ease debugging (Props @Napas / Automattic#15) - Improved - Reduced size of PHP namespace and reorder them to better avoid collisions - Improved - Strip down the distribution PHAR and removed extraneous artifacts from Packagist - Improved - A better build and contribution process
2 parents b773771 + 51b5210 commit 8dc9f5b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+286
-27283
lines changed

.editorconfig

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# top-most EditorConfig file
2+
root = true
3+
4+
# Unix-style newlines with a newline ending every file
5+
[*]
6+
end_of_line = lf
7+
insert_final_newline = true
8+
charset = utf-8
9+
indent_style = space
10+
indent_size = 2
11+
12+
# Tab indentation (no size specified)
13+
[Makefile]
14+
indent_style = tab
15+
16+
#
17+
# Auto generated files
18+
#
19+
[src/**.json]
20+
indent_size = 4
21+
22+
[src/{Thrift,ThriftGenerated}/**.php]
23+
indent_size = 4

.gitattributes

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
src export-ignore
2+
src-thrift export-ignore
3+
.editorconfig export-ignore
4+
.gitattributes export-ignore
5+
.gitignore export-ignore
6+
.gitmodules export-ignore
27
build.php export-ignore
38
example.php export-ignore
9+
LICENSE export-ignore
10+
Makefile export-ignore
11+
README.md export-ignore

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
/composer.lock
2+
/build/
3+
/src/autoload.php
4+
/src/Thrift/
5+
/src/ThriftGenerated/
16
/vendor/
2-
.php-autoload-generator-cache.json

.gitmodules

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[submodule "src-thrift/thrift"]
2+
path = src-thrift/thrift
3+
url = https://github.com/apache/thrift.git
4+
[submodule "src-thrift/hive"]
5+
path = src-thrift/hive
6+
url = https://github.com/apache/hive.git
7+
[submodule "src-thrift/impala"]
8+
path = src-thrift/impala
9+
url = https://github.com/apache/impala.git

Makefile

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
2+
#
3+
# Startup Checks / Utils
4+
#
5+
6+
# Check for prerequisites exist in our PATH
7+
EXECUTABLES = php thrift composer
8+
EXECUTABLES_OK := $(foreach EXEC, $(EXECUTABLES), \
9+
$(if $(shell which $(EXEC)),some string, \
10+
$(error Could not find '$(EXEC)') \
11+
) \
12+
)
13+
14+
# Detect multithread limit
15+
PLATFORM=$(shell uname -s)
16+
ifeq ($(PLATFORM),Darwin)
17+
THREADS := $(shell sysctl -n hw.ncpu)
18+
else ifeq ($(PLATFORM),Linux)
19+
THREADS := $(shell nproc)
20+
else
21+
THREADS := 2
22+
endif
23+
24+
#
25+
# Make Targets
26+
#
27+
28+
default: impala hive thrift
29+
# Lint generated files
30+
find build/gen-php/ThriftGenerated -type f -name "*.php" -print0 | \
31+
xargs -0L1 -P ${THREADS} \
32+
php -l
33+
34+
impala: submodules
35+
# Build error codes thrift file
36+
src-thrift/impala/common/thrift/generate_error_codes.py
37+
mv ErrorCodes.thrift build/
38+
# Remap some dirs to fix file inclusion
39+
@rm -f build/share
40+
ln -s ../src-thrift/thrift/contrib build/share
41+
# Build Impala
42+
thrift --gen php:nsglobal=ThriftGenerated \
43+
-o build \
44+
-I build \
45+
-I src-thrift/hive/metastore/if \
46+
-I src-thrift/hive/service/if \
47+
src-thrift/impala/common/thrift/ImpalaService.thrift
48+
thrift --gen php:nsglobal=ThriftGenerated \
49+
-o build \
50+
-I build \
51+
-I src-thrift/hive/metastore/if \
52+
src-thrift/impala/common/thrift/beeswax.thrift
53+
54+
hive: submodules
55+
thrift --gen php:nsglobal=ThriftGenerated \
56+
-o build \
57+
-I src-thrift/hive \
58+
src-thrift/hive/service/if/TCLIService.thrift
59+
60+
thrift: submodules
61+
62+
submodules:
63+
git submodule update
64+
@mkdir -p build
65+
66+
install: default
67+
@rm -rf src/Thrift
68+
cp -a src-thrift/thrift/lib/php/lib src/Thrift
69+
@rm -rf src/ThriftGenerated
70+
mv build/gen-php/ThriftGenerated src/ThriftGenerated
71+
72+
phar: install composer.lock
73+
vendor/bin/phpab --nolower --output src/autoload.php --basedir src src
74+
php -d phar.readonly=0 build.php
75+
76+
clean-dev: clean
77+
rm -rf vendor
78+
rm -f composer.lock
79+
80+
clean:
81+
rm -rf build
82+
rm -rf src/Thrift
83+
rm -rf src/ThriftGenerated
84+
rm -f src/autoload.php
85+
86+
composer.lock: composer.json
87+
composer install
88+
89+
.PHONY: default impala hive thrift submodules install phar clean-dev clean

README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ Currently the following engines are supported:
88
* *Hive* -- Over the HiveServer2 Thrift interface, SASL is enabled by default so username and password must be provided however this can be turned off with the `setSasl()` method before calling `connect()`.
99
* *Impala* -- Over the Impala Service Thrift interface which extends the Beeswax protocol.
1010

11+
Version Compatibility
12+
---------------------
13+
14+
This library is currently compiled against the Thrift definitions of the following database versions:
15+
16+
- Apache Hive `1.1.0` ([Mar 2015](https://github.com/apache/hive/tree/release-1.1.0))
17+
- Apache Impala `2.12.0` ([Apr 2018](https://github.com/apache/impala/tree/2.12.0))
18+
19+
Using the compiler and base PHP classes of:
20+
21+
- Apache Thrift `0.12.0` ([Oct 2018](https://github.com/apache/thrift/tree/v0.12.0))
22+
1123
Usage Example
1224
-------------
1325

@@ -105,14 +117,10 @@ print_r( $impalaTables );
105117
Developing & Contributing
106118
-------------------------
107119

108-
In order to rebuild this library you will need [Composer](https://getcomposer.org/) to install dev dependencies:
109-
110-
```
111-
$ composer install
112-
```
120+
In order to rebuild this library you will need [Composer](https://getcomposer.org/) to install dev dependencies and [Apache Thrift](https://thrift.apache.org/) to compile client libraries from the Thrift interface definition files.
113121

114-
Once dev tools are installed the phar can be rebuilt using the build script:
122+
Once dev tools are installed the phar can be rebuilt using `make`:
115123

116124
```
117-
$ php -d phar.readonly=0 build.php
125+
$ make clean && make phar
118126
```

ThriftSQL.phar

-517 KB
Binary file not shown.

build.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
<?php
22

3-
// Check we have dev tools
4-
if ( !file_exists( __DIR__ . '/vendor/bin/php-generate-autoload' ) ) {
5-
echo "Please install dev tools with:\n";
6-
echo "$ composer install\n";
7-
exit(1);
8-
}
9-
103
// Check we can write phar
114
if ( !Phar::canWrite() ) {
125
echo "Can not write phar please run build script with:\n";
136
echo "$ php -d phar.readonly=0 {$argv[0]}\n";
147
exit(1);
158
}
169

17-
// Update autoload file
18-
echo "Updating 'src/autoload.php'\n";
19-
echo "\t" . preg_replace( '/\n/', "\n\t", shell_exec(
20-
'./vendor/bin/php-generate-autoload src/autoload.php'
21-
) ) . "\n";
10+
// Check for autoload file
11+
if ( ! file_exists( 'src/autoload.php' ) ) {
12+
echo "Could not find generated autoload file, please use make tool:\n";
13+
echo "$ make phar\n";
14+
exit(1);
15+
}
2216

2317
// Create Stub
2418
echo "Updating 'ThriftSQL.phar'... ";
@@ -29,8 +23,14 @@
2923
EOF;
3024

3125
// Create Phar
32-
$phar = new Phar( 'ThriftSQL.phar', null, 'ThriftSQL.phar' );
26+
$pharFilename = "ThriftSQL.phar";
27+
if ( file_exists( $pharFilename ) ) {
28+
unlink( $pharFilename );
29+
}
30+
$phar = new Phar( $pharFilename );
3331
$phar->buildFromDirectory( __DIR__ . '/src' );
3432
$phar->setStub( $stub );
33+
$phar->setSignatureAlgorithm( Phar::SHA256 );
34+
$phar->compressFiles( Phar::GZ );
3535

3636
echo "Built!\n";

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
}
1515
],
1616
"require": {
17-
"php": ">=5.3.0"
17+
"php": ">=5.5.0"
1818
},
1919
"autoload": {
2020
"files": [ "ThriftSQL.phar" ]
@@ -26,6 +26,6 @@
2626
}
2727
],
2828
"require-dev": {
29-
"jesseschalken/autoload-generator": "^0.2.3"
29+
"theseer/autoload": "1.*"
3030
}
3131
}

0 commit comments

Comments
 (0)