Skip to content

Commit 1247c94

Browse files
committed
fix python ruff
1 parent 63b6a18 commit 1247c94

110 files changed

Lines changed: 1953 additions & 1110 deletions

File tree

Some content is hidden

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

.github/workflows/python-integ-hive.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ on:
1717
branches:
1818
- main
1919
paths:
20-
- python/src/lance_namespace_impls/hive.py
21-
- python/tests/test_hive.py
20+
- python/src/lance_namespace_impls/hive2.py
21+
- python/src/lance_namespace_impls/rest_client.py
22+
- python/tests/test_hive2.py
23+
- python/tests/test_hive2_integration.py
2224
- docker/hive2/**
2325
- .github/workflows/python-integ-hive.yml
2426
pull_request:
@@ -28,8 +30,10 @@ on:
2830
- ready_for_review
2931
- reopened
3032
paths:
31-
- python/src/lance_namespace_impls/hive.py
32-
- python/tests/test_hive.py
33+
- python/src/lance_namespace_impls/hive2.py
34+
- python/src/lance_namespace_impls/rest_client.py
35+
- python/tests/test_hive2.py
36+
- python/tests/test_hive2_integration.py
3337
- docker/hive2/**
3438
- .github/workflows/python-integ-hive.yml
3539
workflow_dispatch:

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ python-integ-test:
156156
python-integ-test-hive:
157157
cd python && make integ-test-hive
158158

159+
.PHONY: python-integ-test-hive2
160+
python-integ-test-hive2:
161+
cd python && make integ-test-hive2
162+
163+
.PHONY: python-integ-test-hive3
164+
python-integ-test-hive3:
165+
cd python && make integ-test-hive3
166+
159167
.PHONY: python-integ-test-polaris
160168
python-integ-test-polaris:
161169
cd python && make integ-test-polaris

docker/hive2/docker-compose.yml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: '3.8'
2-
31
services:
42
postgres-hive2:
53
image: postgres:15
@@ -21,23 +19,27 @@ services:
2119
- hive2-network
2220

2321
hive2-metastore:
24-
image: apache/hive:2.3.9
22+
image: bde2020/hive:2.3.2-postgresql-metastore
2523
container_name: hive2-metastore
2624
depends_on:
2725
postgres-hive2:
2826
condition: service_healthy
2927
environment:
30-
SERVICE_NAME: metastore
31-
DB_DRIVER: postgres
32-
SERVICE_OPTS: >-
33-
-Djavax.jdo.option.ConnectionDriverName=org.postgresql.Driver
34-
-Djavax.jdo.option.ConnectionURL=jdbc:postgresql://postgres-hive2:5432/metastore_db
35-
-Djavax.jdo.option.ConnectionUserName=hive
36-
-Djavax.jdo.option.ConnectionPassword=hive
28+
HIVE_SITE_CONF_javax_jdo_option_ConnectionURL: jdbc:postgresql://postgres-hive2:5432/metastore_db
29+
HIVE_SITE_CONF_javax_jdo_option_ConnectionDriverName: org.postgresql.Driver
30+
HIVE_SITE_CONF_javax_jdo_option_ConnectionUserName: hive
31+
HIVE_SITE_CONF_javax_jdo_option_ConnectionPassword: hive
32+
HIVE_SITE_CONF_datanucleus_autoCreateSchema: "true"
33+
HIVE_SITE_CONF_datanucleus_schema_autoCreateAll: "true"
34+
HIVE_SITE_CONF_hive_metastore_schema_verification: "false"
35+
HIVE_SITE_CONF_hive_metastore_uris: thrift://hive2-metastore:9083
36+
HIVE_SITE_CONF_hive_metastore_warehouse_dir: file:///user/hive/warehouse
37+
CORE_CONF_fs_defaultFS: file:///
38+
SERVICE_PRECONDITION: "postgres-hive2:5432"
3739
ports:
3840
- "9083:9083"
3941
volumes:
40-
- hive2-warehouse:/opt/hive/data/warehouse
42+
- hive2-warehouse:/user/hive/warehouse
4143
- ./postgresql-42.7.3.jar:/opt/hive/lib/postgres.jar
4244
networks:
4345
- hive2-network
@@ -46,7 +48,8 @@ services:
4648
interval: 10s
4749
timeout: 10s
4850
retries: 10
49-
start_period: 30s
51+
start_period: 60s
52+
command: /opt/hive/bin/hive --service metastore
5053

5154
volumes:
5255
hive2-postgres-data:

docker/hive2/postgresql-42.7.3.jar

1.04 MB
Binary file not shown.

docker/hive3/docker-compose.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
version: '3.8'
2-
31
services:
42
postgres-hive3:
53
image: postgres:15
@@ -21,7 +19,7 @@ services:
2119
- hive3-network
2220

2321
hive3-metastore:
24-
image: apache/hive:4.0.0
22+
image: apache/hive:3.1.3
2523
container_name: hive3-metastore
2624
depends_on:
2725
postgres-hive3:
@@ -34,9 +32,11 @@ services:
3432
-Djavax.jdo.option.ConnectionURL=jdbc:postgresql://postgres-hive3:5432/metastore_db
3533
-Djavax.jdo.option.ConnectionUserName=hive
3634
-Djavax.jdo.option.ConnectionPassword=hive
35+
-Dhive.metastore.warehouse.dir=file:///opt/hive/data/warehouse
36+
-Dfs.defaultFS=file:///
3737
ports:
3838
- "9084:9083"
39-
- "9001:9001"
39+
- "9002:9001"
4040
volumes:
4141
- hive3-warehouse:/opt/hive/data/warehouse
4242
- ./postgresql-42.7.3.jar:/opt/hive/lib/postgres.jar

docker/hive3/postgresql-42.7.3.jar

1.04 MB
Binary file not shown.

java/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ integ-test:
143143

144144
.PHONY: integ-test-hive2
145145
integ-test-hive2:
146-
./mvnw test -pl lance-namespace-hive2 -Dtest="*IntegrationTest" -DfailIfNoTests=false
146+
./mvnw test -pl lance-namespace-hive2 -Dtest="*NamespaceIntegration" -DfailIfNoTests=false
147147

148148
.PHONY: integ-test-hive3
149149
integ-test-hive3:
150-
./mvnw test -pl lance-namespace-hive3 -Dtest="*IntegrationTest" -DfailIfNoTests=false
150+
./mvnw test -pl lance-namespace-hive3 -Dtest="*NamespaceIntegration" -DfailIfNoTests=false
151151

152152
.PHONY: integ-test-polaris
153153
integ-test-polaris:

java/lance-namespace-hive2/src/main/java/org/lance/namespace/hive2/Hive2Namespace.java

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import org.lance.namespace.model.CreateEmptyTableResponse;
2727
import org.lance.namespace.model.CreateNamespaceRequest;
2828
import org.lance.namespace.model.CreateNamespaceResponse;
29+
import org.lance.namespace.model.DeregisterTableRequest;
30+
import org.lance.namespace.model.DeregisterTableResponse;
2931
import org.lance.namespace.model.DescribeNamespaceRequest;
3032
import org.lance.namespace.model.DescribeNamespaceResponse;
3133
import org.lance.namespace.model.DescribeTableRequest;
@@ -203,11 +205,12 @@ public DescribeNamespaceResponse describeNamespace(DescribeNamespaceRequest requ
203205
public DropNamespaceResponse dropNamespace(DropNamespaceRequest request) {
204206
ObjectIdentifier id = ObjectIdentifier.of(request.getId());
205207
String mode = request.getMode() != null ? request.getMode().toLowerCase() : "fail";
208+
String behavior = request.getBehavior() != null ? request.getBehavior() : "Restrict";
206209

207210
ValidationUtil.checkArgument(
208211
!id.isRoot() && id.levels() <= 1, "Expect a 1-level namespace but get %s", id);
209212

210-
Map<String, String> properties = doDropNamespace(id, mode);
213+
Map<String, String> properties = doDropNamespace(id, mode, behavior);
211214

212215
DropNamespaceResponse response = new DropNamespaceResponse();
213216
response.setProperties(properties);
@@ -302,7 +305,20 @@ public CreateEmptyTableResponse createEmptyTable(CreateEmptyTableRequest request
302305
return response;
303306
}
304307

305-
// Removed: dropTable(DropTableRequest) - using default implementation from interface
308+
@Override
309+
public DeregisterTableResponse deregisterTable(DeregisterTableRequest request) {
310+
ObjectIdentifier tableId = ObjectIdentifier.of(request.getId());
311+
312+
ValidationUtil.checkArgument(
313+
tableId.levels() == 2, "Expect 2-level table identifier but get %s", tableId);
314+
315+
String location = doDropTable(tableId);
316+
317+
DeregisterTableResponse response = new DeregisterTableResponse();
318+
response.setId(request.getId());
319+
response.setLocation(location);
320+
return response;
321+
}
306322

307323
public void setConf(Configuration conf) {
308324
this.hadoopConf = conf;
@@ -538,7 +554,7 @@ protected String doDropTable(ObjectIdentifier id) {
538554
}
539555
}
540556

541-
protected Map<String, String> doDropNamespace(ObjectIdentifier id, String mode) {
557+
protected Map<String, String> doDropNamespace(ObjectIdentifier id, String mode, String behavior) {
542558
String db = id.levelAtListPos(0).toLowerCase();
543559

544560
try {
@@ -552,14 +568,17 @@ protected Map<String, String> doDropNamespace(ObjectIdentifier id, String mode)
552568
}
553569
}
554570

555-
// Check if database contains tables (RESTRICT mode only)
556-
List<String> tables = doListTables(db);
557-
if (!tables.isEmpty()) {
558-
throw new InvalidInputException(
559-
String.format(
560-
"Database %s is not empty. Contains %d tables: %s", db, tables.size(), tables),
561-
HiveMetaStoreError.getType(),
562-
db);
571+
// Check if database contains tables (RESTRICT behavior only, not for Cascade)
572+
boolean cascade = "Cascade".equalsIgnoreCase(behavior);
573+
if (!cascade) {
574+
List<String> tables = doListTables(db);
575+
if (!tables.isEmpty()) {
576+
throw new InvalidInputException(
577+
String.format(
578+
"Database %s is not empty. Contains %d tables: %s", db, tables.size(), tables),
579+
HiveMetaStoreError.getType(),
580+
db);
581+
}
563582
}
564583

565584
// Collect database properties before dropping
@@ -581,9 +600,10 @@ protected Map<String, String> doDropNamespace(ObjectIdentifier id, String mode)
581600
}
582601

583602
// Drop the database
603+
final boolean cascadeDrop = cascade;
584604
clientPool.run(
585605
client -> {
586-
client.dropDatabase(db, false, true, false);
606+
client.dropDatabase(db, false, true, cascadeDrop);
587607
return null;
588608
});
589609

java/lance-namespace-hive2/src/test/java/org/lance/namespace/hive2/TestHive2NamespaceIntegration.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
import org.lance.namespace.model.CreateEmptyTableResponse;
1919
import org.lance.namespace.model.CreateNamespaceRequest;
2020
import org.lance.namespace.model.CreateNamespaceResponse;
21+
import org.lance.namespace.model.DeregisterTableRequest;
2122
import org.lance.namespace.model.DescribeNamespaceRequest;
2223
import org.lance.namespace.model.DescribeNamespaceResponse;
2324
import org.lance.namespace.model.DescribeTableRequest;
2425
import org.lance.namespace.model.DescribeTableResponse;
2526
import org.lance.namespace.model.DropNamespaceRequest;
26-
import org.lance.namespace.model.DropTableRequest;
2727
import org.lance.namespace.model.ListNamespacesRequest;
2828
import org.lance.namespace.model.ListNamespacesResponse;
2929
import org.lance.namespace.model.ListTablesRequest;
@@ -209,10 +209,10 @@ public void testTableOperations() {
209209
ListTablesResponse listResponse = namespace.listTables(listRequest);
210210
assertThat(listResponse.getTables()).contains(tableName);
211211

212-
// Drop table
213-
DropTableRequest dropRequest = new DropTableRequest();
214-
dropRequest.setId(Arrays.asList(testDatabase, tableName));
215-
namespace.dropTable(dropRequest);
212+
// Deregister table
213+
DeregisterTableRequest deregisterRequest = new DeregisterTableRequest();
214+
deregisterRequest.setId(Arrays.asList(testDatabase, tableName));
215+
namespace.deregisterTable(deregisterRequest);
216216

217217
// Verify table doesn't exist
218218
assertThatThrownBy(() -> namespace.describeTable(describeRequest))
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
----------------------------------------------------------------
2+
Tue Dec 30 21:25:14 PST 2025:
3+
Booting Derby version The Apache Software Foundation - Apache Derby - 10.14.2.0 - (1828579): instance a816c00e-019b-72de-0fb6-00000746a618
4+
on database directory /Users/zhaoqinye/oss/lance-namespace-impls/java/lance-namespace-hive3/metastore_db with class loader jdk.internal.loader.ClassLoaders$AppClassLoader@5ffd2b27
5+
Loaded from file:/Users/zhaoqinye/.m2/repository/org/apache/derby/derby/10.14.2.0/derby-10.14.2.0.jar
6+
java.vendor=Amazon.com Inc.
7+
java.runtime.version=17.0.14+7-LTS
8+
user.dir=/Users/zhaoqinye/oss/lance-namespace-impls/java/lance-namespace-hive3
9+
os.name=Mac OS X
10+
os.arch=aarch64
11+
os.version=15.5
12+
derby.system.home=null
13+
Database Class Loader started - derby.database.classpath=''

0 commit comments

Comments
 (0)